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.
25 #include "CGameData.h"
29 completedWorld
= false;
32 void GameData::clear()
37 void GameData::destroy()
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
);
60 data
->set(key
, value
, current
, target
);
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
);
82 dataList
.add(newData
);
85 void GameData::setMIARescueCount(const char *key
, int rescues
, int total
)
87 Data
*data
= (Data
*)dataList
.getHead();
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
;
106 data
->set(newKey
, "MIAs", rescues
, total
);
111 bool GameData::MIARescued(const char *stageName
, const char *name
)
113 Data
*data
= (Data
*)dataList
.getHead();
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();
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
);
152 void GameData::getObjectiveValues(const char *stageName
, const char *name
, int *current
, int *target
)
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
);
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)
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)
206 bool GameData::levelPrefectlyCleared(const char *level
)
208 Data
*data
= (Data
*)dataList
.getHead();
212 while (data
->next
!= NULL
)
214 data
= (Data
*)data
->next
;
216 if (strcmp(data
->key
, level
) == 0)
220 if (!data
->isComplete())
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)
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
;
282 if (data
->isComplete())
286 if ((total
== 0) || (completed
== 0))
289 percentage
= (completed
/ total
);
292 return (int)percentage
;