]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/objectives.cpp
Do not use DESTDIR in PREFIX, but only in the install target.
[quix0rs-blobwars.git] / src / objectives.cpp
1 /*
2 Copyright (C) 2004-2010 Parallel Realities
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #include "objectives.h"
22
23 void adjustObjectives()
24 {
25         bool needRequired = false;
26
27         Entity *mia = (Entity*)map.miaList.getHead();
28
29         while (mia->next != NULL)
30         {
31                 mia = (Entity*)mia->next;
32
33                 if (gameData.MIARescued(map.name, mia->name))
34                 {
35                         mia->health = 0;
36                         map.foundMIAs++;
37                 }
38         }
39
40         if (map.foundMIAs >= map.requiredMIAs)
41         {
42                 map.requiredMIAs = map.totalMIAs;
43                 needRequired = true;
44         }
45         
46         if (game.skill == 3)
47         {
48                 map.requiredMIAs = map.totalMIAs;
49                 needRequired = true;
50         }
51         
52         int current = 0;
53         int target = 0;
54
55         Objective *objective = (Objective*)map.objectiveList.getHead();
56         
57         bool previouslyCleared = gameData.stagePreviouslyCleared(map.name);
58
59         while (objective->next != NULL)
60         {       
61                 objective = (Objective*)objective->next;
62
63                 if (game.skill == 0)
64                 {
65                         objective->required = false;
66                 }
67
68                 if (game.skill >= 3)
69                 {
70                         objective->required = true;
71                 }
72
73                 if (needRequired)
74                 {
75                         objective->required = true;
76                 }
77
78                 if (previouslyCleared)
79                 {
80                         if (gameData.objectiveCompleted(map.name, objective->description))
81                         {
82                                 objective->completed = true;
83         
84                                 debug(("Objective %s has been completed\n", objective->description));
85                         }
86         
87                         gameData.getObjectiveValues(map.name, objective->description, &current, &target);
88                         objective->currentValue = current;
89                         objective->targetValue = target;
90                         
91                         // Make sure that gameplay adjustments are catered for...
92                         if (!objective->completed)
93                         {
94                                 Math::limitInt(&objective->currentValue, 0, objective->targetValue);
95                                 
96                                 if (objective->currentValue == objective->targetValue)
97                                 {
98                                         objective->completed = true;
99                                         
100                                         debug(("Objective %s has been completed (gameplay adjustment!)\n", objective->description));
101                                 }
102                         }
103                 }
104         }
105 }
106
107 bool allObjectivesCompleted()
108 {
109         if (map.foundMIAs < map.requiredMIAs)
110                 return false;
111
112         Objective *objective = (Objective*)map.objectiveList.getHead();
113
114         while (objective->next != NULL)
115         {
116                 objective = (Objective*)objective->next;
117
118                 if ((objective->required) && (!objective->completed))
119                         return false;
120         }
121
122         return true;
123 }
124
125 bool perfectlyCompleted()
126 {
127         if (map.foundMIAs < map.totalMIAs)
128                 return false;
129
130         Objective *objective = (Objective*)map.objectiveList.getHead();
131
132         while (objective->next != NULL)
133         {
134                 objective = (Objective*)objective->next;
135
136                 if (!objective->completed)
137                         return false;
138         }
139
140         return true;
141 }
142
143 bool requiredEnemy(const char *name)
144 {
145         Objective *objective = (Objective*)map.objectiveList.getHead();
146
147         while (objective->next != NULL)
148         {
149                 objective = (Objective*)objective->next;
150
151                 if (strcmp(objective->target, name) == 0)
152                 {
153                         return true;
154                 }
155         }
156
157         return false;
158 }
159
160 bool requiredObjectivesCompleted()
161 {
162         if (map.foundMIAs < map.requiredMIAs)
163         {
164                 return false;
165         }
166
167         Objective *objective = (Objective*)map.objectiveList.getHead();
168
169         while (objective->next != NULL)
170         {
171                 objective = (Objective*)objective->next;
172
173                 if (strcmp(objective->target, "Exit") == 0)
174                 {
175                         continue;
176                 }
177
178                 if ((objective->required) && (!objective->completed))
179                 {
180                         return false;
181                 }
182         }
183
184         return true;
185 }
186
187 /*
188 Used by the skip level cheat
189 */
190 void autoCompleteAllObjectives(bool allObjectives)
191 {
192         if (allObjectives)
193         {
194                 map.requiredMIAs = map.totalMIAs;
195                 map.foundMIAs = map.totalMIAs;
196         }
197         else
198         {
199                 map.foundMIAs = map.requiredMIAs;
200         }
201         
202         map.foundItems = map.totalItems;
203
204         Objective *objective = (Objective*)map.objectiveList.getHead();
205
206         while (objective->next != NULL)
207         {
208                 objective = (Objective*)objective->next;
209                 
210                 if (allObjectives)
211                 {
212                         objective->completed = true;
213                         objective->currentValue = objective->targetValue;
214                 }
215                 else
216                 {
217                         if (objective->required)
218                         {
219                                 objective->completed = true;
220                                 objective->currentValue = objective->targetValue;
221                         }
222                 }
223         }
224         
225         int required = map.foundMIAs;
226
227         Entity *mia = (Entity*)map.miaList.getHead();
228
229         while (mia->next != NULL)
230         {
231                 mia = (Entity*)mia->next;
232                 mia->health = 0;
233                 required--;
234                 
235                 if (required == 0)
236                         break;
237         }
238 }
239
240 void checkObjectives(const char *name, bool alwaysInform)
241 {
242         Objective *objective = (Objective*)map.objectiveList.getHead();
243
244         char message[256];
245         
246         int requiredValue;
247
248         while (objective->next != NULL)
249         {
250                 objective = (Objective*)objective->next;
251
252                 if (!objective->completed)
253                 {
254                         if (strcmp(objective->target, name) == 0)
255                         {
256                                 if (strstr(objective->target, "Combo-"))
257                                 {
258                                         objective->currentValue = game.currentComboHits;
259                                         Math::limitInt(&objective->currentValue, 0, objective->targetValue);
260                                 }
261                                 else
262                                 {
263                                         objective->currentValue++;
264                                 }
265
266                                 requiredValue = objective->targetValue - objective->currentValue;
267
268                                 if (objective->currentValue == objective->targetValue)
269                                 {
270                                         if (!map.isBossMission)
271                                         {
272                                                 snprintf(message, sizeof message, _("%s - Objective Completed - Check Point Reached!"), _(objective->description));
273                                                 game.setObjectiveCheckPoint();
274                                         }
275                                         else
276                                         {
277                                                 snprintf(message, sizeof message, _("%s - Objective Completed"), _(objective->description));
278                                         }
279
280                                         if (strcmp(objective->description, "Get the Aqua Lung") == 0)
281                                         {
282                                                 snprintf(message, sizeof message, "Got the Aqua Lung! You can now swim forever!");
283                                                 game.hasAquaLung = true;
284                                                 presentPlayerMedal("Aqua_Lung");
285                                         }
286
287                                         if (strcmp(objective->description, "Get the Jetpack") == 0)
288                                         {
289                                                 snprintf(message, sizeof message, "Got the Jetpack! Press SPACE to Activate!");
290                                                 game.hasJetPack = true;
291                                                 presentPlayerMedal("Jetpack");
292                                         }
293
294                                         engine.setInfoMessage(message, 9, INFO_OBJECTIVE);
295                                         objective->completed = true;
296                                         game.totalObjectivesCompleted++;
297
298                                 }
299                                 else if (!strstr(objective->target, "Combo-"))
300                                 {
301                                         if ((requiredValue % 10 == 0) || (requiredValue <= 10) || (alwaysInform))
302                                         {
303                                                 switch (Math::prand() % 3)
304                                                 {
305                                                         case 0:
306                                                                 snprintf(message, sizeof message, _("%s - %d more to go..."), _(objective->description), requiredValue);
307                                                                 break;
308                                                         case 1:
309                                                                 snprintf(message, sizeof message, _("%s - need %d more"), _(objective->description), requiredValue);
310                                                                 break;
311                                                         case 2:
312                                                                 snprintf(message, sizeof message, _("%s - %d of %d"), _(objective->description), objective->currentValue, objective->targetValue);
313                                                                 break;
314                                                 }
315                                                 
316                                                 engine.setInfoMessage(message, 1, INFO_NORMAL);
317                                         }
318                                         else
319                                         {
320                                                 return;
321                                         }
322                                 }
323                                 else
324                                 {
325                                         continue;
326                                 }
327                         }
328                 }
329         }
330 }