1 /*
2 Copyright (C) 2004 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 "headers.h"
22 
GameData()23 GameData::GameData()
24 {
25 	shownTitles = false;
26 
27 	gamma = 10;
28 	soundVolume = 128;
29 	musicVolume = 100;
30 
31 	strcpy(directorySearchPath, "/home");
32 
33 	#if !UNIX
34 		strcpy(directorySearchPath, getenv("PROGRAMFILES"));
35 	#endif
36 
37 	maxDirectories = 0;
38 	maxFiles = 0;
39 	score = 0;
40 	activeViruses = 0;
41 	level = 1;
42 	activeDirs = 0;
43 	kernelPower = 300;
44 	skill = 0;
45 
46 	threadStopTimer = 0;
47 	threadStops = 0;
48 
49 	for (int x = 0 ; x < 5 ; x++)
50 		for (int y = 0 ; y < 5 ; y++)
51 			map[x][y] = 0;
52 
53 	for (int i = 0 ; i < 5 ; i++)
54 	{
55 		highScore[i][0].set("MyDoom", 1000000 / ((i * 2) + 1), 100, 1);
56 		highScore[i][1].set("Blaster", 250000 / ((i * 2)  + 1), 100, 1);
57 		highScore[i][2].set("SoBigF", 900000 / ((i * 2)  + 1), 100, 1);
58 		highScore[i][3].set("Klez", 1000000 / ((i * 2) + 1), 100, 1);
59 		highScore[i][4].set("iloveyou", 800000 / ((i * 2)  + 1), 100, 1);
60 		highScore[i][5].set("Melissa", 700000 / ((i * 2)  + 1), 100, 1);
61 		highScore[i][6].set("Slammer", 600000 / ((i * 2)  + 1), 100, 1);
62 		highScore[i][7].set("Sober", 500000 / ((i * 2)  + 1), 100, 1);
63 		highScore[i][8].set("Bugbear", 400000 / ((i * 2)  + 1), 100, 1);
64 		highScore[i][9].set("Code Red", 300000 / ((i * 2)  + 1), 100, 1);
65 	}
66 
67 	nightmareCount = 100;
68 }
69 
~GameData()70 GameData::~GameData()
71 {
72 	destroy();
73 }
74 
clear()75 void GameData::clear()
76 {
77 	score = 0;
78 	activeViruses = 0;
79 	level = 1;
80 
81 	virusesKilled = 0;
82 	roundVirusesKilled = 0;
83 
84 	filesLost = 0;
85 	roundFilesLost = 0;
86 
87 	dirsLost = 0;
88 	roundDirsLost = 0;
89 
90 	biggestChain = 0;
91 	roundBiggestChain = 0;
92 
93 	lastVirusKilled = 0;
94 
95 	kernelPower = 300;
96 
97 	threadStopTimer = 0;
98 	threadStops = 0;
99 
100 	for (int x = 0 ; x < 5 ; x++)
101 		for (int y = 0 ; y < 5 ; y++)
102 			map[x][y] = 0;
103 
104 	virusList.clear();
105 	particleList.clear();
106 	itemList.clear();
107 
108 	Directory *dir = (Directory*)directoryList.getHead();
109 
110 	while (dir->next != NULL)
111 	{
112 		dir = (Directory*)dir->next;
113 		dir->active = false;
114 		dir->x = dir->y = -1;
115 	}
116 }
117 
resetForNextRound()118 void GameData::resetForNextRound()
119 {
120 	roundVirusesKilled = 0;
121 	roundFilesLost = 0;
122 	roundDirsLost = 0;
123 	roundBiggestChain = 0;
124 	currentChain = 0;
125 	lastVirusKilled = 50;
126 	roundItemsCollected = 0;
127 
128 	for (int i = 0 ; i < 4 ; i++)
129 		base[i].place();
130 
131 	kernelPower = 300;
132 
133 	itemList.clear();
134 }
135 
destroy()136 void GameData::destroy()
137 {
138 	virusList.clear();
139 	directoryList.clear();
140 	particleList.clear();
141 	itemList.clear();
142 }
143 
addDirectory(const char * name)144 Directory *GameData::addDirectory(const char *name)
145 {
146 	char string[1024];
147 	char *realName, *previousName;
148 
149 	strcpy(string, name);
150 
151 	realName = strtok(string, "/");
152 	previousName = realName;
153 
154 	while (realName != NULL)
155 	{
156 		previousName = realName;
157 		realName = strtok(NULL, "/");
158 	}
159 
160 	name = previousName;
161 
162 	Directory *dir = (Directory*)directoryList.getHead();
163 
164 	while (dir->next != NULL)
165 	{
166 		dir = (Directory*)dir->next;
167 
168 		if (strcmp(dir->name, name) == 0)
169 		{
170 			debug(("Directory '%s' already exists. Skipping.\n", dir->name));
171 			return dir;
172 		}
173 	}
174 
175 	dir = new Directory();
176 	strncpy(dir->name, name, 49);
177 	directoryList.add(dir);
178 	maxDirectories++;
179 
180 	//debug(("Added Directory '%s'\n", dir->name));
181 
182 	return dir;
183 }
184 
addItem(Item * item)185 void GameData::addItem(Item *item)
186 {
187 	itemList.add(item);
188 }
189 
addVirus(Virus * virus)190 void GameData::addVirus(Virus *virus)
191 {
192 	virusList.add(virus);
193 }
194 
addParticle(Particle * particle)195 void GameData::addParticle(Particle *particle)
196 {
197 	particleList.add(particle);
198 }
199 
removeEmptyDirectories()200 void GameData::removeEmptyDirectories()
201 {
202 	Directory *dir = (Directory*)directoryList.getHead();
203 	Directory *previous;
204 
205 	while (dir->next != NULL)
206 	{
207 		previous = dir;
208 		dir = (Directory*)dir->next;
209 
210 		if (dir->fileCount == 0)
211 		{
212 			debug(("Directory '%s' is empty. Removing...\n", dir->name));
213 			directoryList.remove(previous, dir);
214 			dir = previous;
215 			maxDirectories--;
216 		}
217 	}
218 }
219 
220 
getRandomDirectory(bool active)221 Directory *GameData::getRandomDirectory(bool active)
222 {
223 	Directory *dir = (Directory*)directoryList.getHead();
224 
225 	int r = rand() % maxDirectories;
226 	int i = 0;
227 
228 	while (dir->next != NULL)
229 	{
230 		dir = (Directory*)dir->next;
231 		if ((r == i) && (dir->active == active))
232 			return dir;
233 
234 		i++;
235 	}
236 
237 	return NULL;
238 }
239 
buildActiveDirList(int amount)240 void GameData::buildActiveDirList(int amount)
241 {
242 	int sanity = 0;
243 	int i = 0;
244 
245 	Directory *dir = (Directory*)directoryList.getHead();
246 
247 	while (true)
248 	{
249 		dir = getRandomDirectory(false);
250 
251 		if (dir != NULL)
252 		{
253 			dir->active = true;
254 			i++;
255 
256 			if (i == amount)
257 				break;
258 		}
259 
260 		sanity++;
261 
262 		if (sanity == 10000)
263 		{
264 			printf("Made 10,000 unsuccessful attempts to grab %d inactives directories!!\n", amount);
265 			exit(1);
266 		}
267 	}
268 }
269