2 Copyright (C) 2004-2010 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.
25 completedWorld = false;
28 void GameData::clear()
33 void GameData::destroy()
38 void GameData::addCompletedObjective(const char *key, const char *value, int current, int target)
40 Data *data = (Data*)dataList.getHead();
42 while (data->next != NULL)
44 data = (Data*)data->next;
45 if (strcmp(key, data->key) == 0)
47 if (strcmp(value, data->value) == 0)
49 data->set(key, value, current, target);
56 data->set(key, value, current, target);
61 void GameData::addCompletedObjective(Data *newData)
63 Data *data = (Data*)dataList.getHead();
65 while (data->next != NULL)
67 data = (Data*)data->next;
68 if (strcmp(data->key, newData->key) == 0)
70 if (strcmp(data->value, newData->value) == 0)
72 data->set(newData->key, newData->value, newData->current, newData->target);
78 dataList.add(newData);
81 void GameData::setMIARescueCount(const char *key, int rescues, int total)
83 Data *data = (Data*)dataList.getHead();
86 snprintf(newKey, sizeof newKey, "%s MIAs", key);
88 while (data->next != NULL)
90 data = (Data*)data->next;
91 if (strcmp(newKey, data->key) == 0)
93 strlcpy(data->value, "MIAs", sizeof data->value);
94 data->current = rescues;
102 data->set(newKey, "MIAs", rescues, total);
107 bool GameData::MIARescued(const char *stageName, char *name)
109 Data *data = (Data*)dataList.getHead();
112 snprintf(newName, sizeof newName, "MIA_%s", name);
114 while (data->next != NULL)
116 data = (Data*)data->next;
117 if (strcmp(data->key, stageName) == 0)
119 if (strcmp(data->value, newName) == 0)
121 return data->isComplete();
129 bool GameData::objectiveCompleted(const char *stageName, const char *name)
131 Data *data = (Data*)dataList.getHead();
133 while (data->next != NULL)
135 data = (Data*)data->next;
136 if (strcmp(data->key, stageName) == 0)
138 if (strcmp(data->value, name) == 0)
140 return (data->current == data->target);
148 void GameData::getObjectiveValues(const char *stageName, const char *name, int *current, int *target)
153 Data *data = (Data*)dataList.getHead();
155 while (data->next != NULL)
157 data = (Data*)data->next;
158 if (strcmp(data->key, stageName) == 0)
160 if (strcmp(data->value, name) == 0)
162 data->getCurrentTarget(current, target);
169 bool GameData::stagePreviouslyCleared(const char *stageName)
171 Data *data = (Data*)dataList.getHead();
173 while (data->next != NULL)
175 data = (Data*)data->next;
176 if (strcmp(data->key, stageName) == 0)
185 bool GameData::isCompleted(const char *key, const char *value)
187 Data *data = (Data*)dataList.getHead();
189 while (data->next != NULL)
191 data = (Data*)data->next;
192 if (strcmp(key, data->key) == 0)
194 if (strcmp(value, data->value) == 0)
202 bool GameData::levelPrefectlyCleared(const char *level)
204 Data *data = (Data*)dataList.getHead();
208 while (data->next != NULL)
210 data = (Data*)data->next;
212 if (strcmp(data->key, level) == 0)
216 if (!data->isComplete())
227 bool GameData::requiredLevelCleared(const char *requiredLevel)
229 Data *data = (Data*)dataList.getHead();
231 while (data->next != NULL)
233 data = (Data*)data->next;
235 if (strcmp(data->key, requiredLevel) == 0)
245 Whether or not all the levels in the game have been unlocked
247 void GameData::calculateWorldCompleted()
249 completedWorld = false;
251 Data *data = (Data*)dataList.getHead();
253 while (data->next != NULL)
255 data = (Data*)data->next;
257 if (strcmp(data->key, "BioMech HQ") == 0)
259 completedWorld = true;
264 int GameData::getPercentageComplete()
266 float percentage, total, completed;
268 total = completed = percentage = 0;
270 Data *data = (Data*)dataList.getHead();
272 while (data->next != NULL)
274 data = (Data*)data->next;
278 if (data->isComplete())
282 if ((total == 0) || (completed == 0))
285 percentage = (completed / total);
288 return (int)percentage;