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