Removed that logo from this bramch aswell..
[dbw.git] / src / CGameData.cpp
blob35868f1eaf9d0e01bef29abc2f4558cb9e5614e3
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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 <cstdio>
23 #include <cstring>
25 #include "CGameData.h"
27 GameData::GameData()
29 completedWorld = false;
32 void GameData::clear()
34 dataList.clear();
37 void GameData::destroy()
39 clear();
42 void GameData::addCompletedObjective(const char *key, const char *value, int current, int target)
44 Data *data = (Data*)dataList.getHead();
46 while (data->next != NULL)
48 data = (Data*)data->next;
49 if (strcmp(key, data->key) == 0)
51 if (strcmp(value, data->value) == 0)
53 data->set(key, value, current, target);
54 return;
59 data = new Data();
60 data->set(key, value, current, target);
62 dataList.add(data);
65 void GameData::addCompletedObjective(Data *newData)
67 Data *data = (Data*)dataList.getHead();
69 while (data->next != NULL)
71 data = (Data*)data->next;
72 if (strcmp(data->key, newData->key) == 0)
74 if (strcmp(data->value, newData->value) == 0)
76 data->set(newData->key, newData->value, newData->current, newData->target);
77 return;
82 dataList.add(newData);
85 void GameData::setMIARescueCount(const char *key, int rescues, int total)
87 Data *data = (Data*)dataList.getHead();
89 char newKey[100];
90 sprintf(newKey, "%s MIAs", key);
92 while (data->next != NULL)
94 data = (Data*)data->next;
95 if (strcmp(newKey, data->key) == 0)
97 strcpy(data->value, "MIAs");
98 data->current = rescues;
99 data->target = total;
100 return;
104 data = new Data();
106 data->set(newKey, "MIAs", rescues, total);
108 dataList.add(data);
111 bool GameData::MIARescued(const char *stageName, const char *name)
113 Data *data = (Data*)dataList.getHead();
115 char newName[100];
116 sprintf(newName, "MIA_%s", name);
118 while (data->next != NULL)
120 data = (Data*)data->next;
121 if (strcmp(data->key, stageName) == 0)
123 if (strcmp(data->value, newName) == 0)
125 return data->isComplete();
130 return false;
133 bool GameData::objectiveCompleted(const char *stageName, const char *name)
135 Data *data = (Data*)dataList.getHead();
137 while (data->next != NULL)
139 data = (Data*)data->next;
140 if (strcmp(data->key, stageName) == 0)
142 if (strcmp(data->value, name) == 0)
144 return (data->current == data->target);
149 return false;
152 void GameData::getObjectiveValues(const char *stageName, const char *name, int *current, int *target)
154 *current = -1;
155 *target = -1;
157 Data *data = (Data*)dataList.getHead();
159 while (data->next != NULL)
161 data = (Data*)data->next;
162 if (strcmp(data->key, stageName) == 0)
164 if (strcmp(data->value, name) == 0)
166 data->getCurrentTarget(current, target);
167 return;
173 bool GameData::stagePreviouslyCleared(const char *stageName)
175 Data *data = (Data*)dataList.getHead();
177 while (data->next != NULL)
179 data = (Data*)data->next;
180 if (strcmp(data->key, stageName) == 0)
182 return true;
186 return false;
189 bool GameData::isCompleted(const char *key, const char *value)
191 Data *data = (Data*)dataList.getHead();
193 while (data->next != NULL)
195 data = (Data*)data->next;
196 if (strcmp(key, data->key) == 0)
198 if (strcmp(value, data->value) == 0)
199 return true;
203 return false;
206 bool GameData::levelPrefectlyCleared(const char *level)
208 Data *data = (Data*)dataList.getHead();
210 bool found = false;
212 while (data->next != NULL)
214 data = (Data*)data->next;
216 if (strcmp(data->key, level) == 0)
218 found = true;
220 if (!data->isComplete())
221 return false;
225 if (!found)
226 return false;
228 return true;
231 bool GameData::requiredLevelCleared(const char *requiredLevel)
233 Data *data = (Data*)dataList.getHead();
235 while (data->next != NULL)
237 data = (Data*)data->next;
239 if (strcmp(data->key, requiredLevel) == 0)
241 return true;
245 return false;
249 Whether or not all the levels in the game have been unlocked
251 void GameData::calculateWorldCompleted()
253 completedWorld = false;
255 Data *data = (Data*)dataList.getHead();
257 while (data->next != NULL)
259 data = (Data*)data->next;
261 if (strcmp(data->key, "BioMech HQ") == 0)
263 completedWorld = true;
268 int GameData::getPercentageComplete()
270 float percentage, total, completed;
272 total = completed = percentage = 0;
274 Data *data = (Data*)dataList.getHead();
276 while (data->next != NULL)
278 data = (Data*)data->next;
280 total++;
282 if (data->isComplete())
283 completed++;
286 if ((total == 0) || (completed == 0))
287 return 0;
289 percentage = (completed / total);
290 percentage *= 100;
292 return (int)percentage;