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 "headers.h"
23 
Game()24 Game::Game()
25 {
26 	musicVol = 100;
27 	soundVol = 128;
28 	output = 2;
29 	brightness = 10;
30 
31 	gore = 1;
32 	skill = 1;
33 
34 	clear();
35 }
36 
clear()37 void Game::clear()
38 {
39 	hasAquaLung = hasJetPack = continueFromCheckPoint = false;
40 	score = stagesCleared = 0;
41 	totalHours = totalMinutes = totalSeconds = 0;
42 	currentMissionHours = currentMissionMinutes = currentMissionSeconds = 0;
43 	totalEnemiesDefeated = totalItemsCollected = totalBonusesCollected = 0;
44 	totalObjectivesCompleted = totalMIAsRescued = 0;
45 	currentMissionEnemiesDefeated = currentMissionItemsCollected = 0;
46 	stagesCleared = 0;
47 
48 	lastComboTime = 0;
49 	currentComboHits = maxComboHits = 0;
50 
51 	autoSave = 1;
52 	autoSaveSlot = 0;
53 
54 	currentWeapon = 0;
55 	for (int i = 0 ; i < 5 ; i++)
56 	{
57 		bulletsHit[i] = bulletsFired[i] = 0;
58 	}
59 
60 	strlcpy(mapName, "data/grasslands1", sizeof mapName);
61 	strlcpy(stageName, "Grasslands", sizeof stageName);
62 
63 	continuesUsed = 0;
64 	levelsStarted = 0;
65 	escapes = 0;
66 
67 	canContinue = 0;
68 }
69 
destroy()70 void Game::destroy()
71 {
72 	clear();
73 }
74 
incrementMissionTime()75 void Game::incrementMissionTime()
76 {
77 	currentMissionSeconds++;
78 	if (currentMissionSeconds == 60)
79 	{
80 		currentMissionSeconds = 0;
81 		currentMissionMinutes++;
82 		if (currentMissionMinutes == 60)
83 		{
84 			currentMissionMinutes = 0;
85 			currentMissionHours++;
86 		}
87 	}
88 }
89 
setObjectiveCheckPoint()90 void Game::setObjectiveCheckPoint()
91 {
92 	objectiveCheckPointX = checkPointX;
93 	objectiveCheckPointY = checkPointY;
94 	canContinue = 3;
95 }
96 
useObjectiveCheckPoint()97 void Game::useObjectiveCheckPoint()
98 {
99 	checkPointX = objectiveCheckPointX;
100 	checkPointY = objectiveCheckPointY;
101 	continuesUsed++;
102 	canContinue--;
103 }
104 
setCheckPoint(float x,float y)105 void Game::setCheckPoint(float x, float y)
106 {
107 	checkPointX = (int)x;
108 	checkPointY = (int)y;
109 }
110 
getCheckPoint(float * x,float * y) const111 void Game::getCheckPoint(float *x, float *y) const
112 {
113 	*x = checkPointX;
114 	*y = checkPointY;
115 }
116 
doCombo()117 void Game::doCombo()
118 {
119 	if (lastComboTime == 0)
120 		currentComboHits = 0;
121 
122 	currentComboHits++;
123 
124 	if (currentComboHits > maxComboHits)
125 		maxComboHits = currentComboHits;
126 
127 	lastComboTime = 25;
128 
129 	Math::limitChar(&maxComboHits, 0, 99);
130 	Math::limitChar(&currentComboHits, 0, 99);
131 }
132 
incBulletsFired()133 void Game::incBulletsFired()
134 {
135 	bulletsFired[currentWeapon]++;
136 }
137 
incBulletsHit()138 void Game::incBulletsHit()
139 {
140 	bulletsHit[currentWeapon]++;
141 }
142 
getWeaponAccuracy(int weapon)143 int Game::getWeaponAccuracy(int weapon)
144 {
145 	if (bulletsHit[weapon])
146 	{
147 		return (int)(((0.0 + bulletsHit[weapon]) / (0.0 + bulletsFired[weapon])) * 100.0);
148 	}
149 
150 	return 0;
151 }
152 
getTotalBulletsFired() const153 int Game::getTotalBulletsFired() const
154 {
155 	return bulletsFired[0] + bulletsFired[1] + bulletsFired[2] + bulletsFired[3] + bulletsFired[4];
156 }
157 
getTotalAccuracy()158 int Game::getTotalAccuracy()
159 {
160 	int fired = getTotalBulletsFired();
161 	int hits = bulletsHit[0] + bulletsHit[1] + bulletsHit[2] + bulletsHit[3] + bulletsHit[4];
162 
163 	if (hits)
164 	{
165 		return (int)(((0.0 + hits) / (0.0 + fired)) * 100.0);
166 	}
167 
168 	return 0;
169 }
170 
getMostUsedWeapon()171 int Game::getMostUsedWeapon()
172 {
173 	unsigned int mostUsed = 0;
174 	unsigned int mostFired = 0;
175 
176 	for (int i = 0 ; i < 5 ; i++)
177 	{
178 		if (bulletsFired[i] > mostFired)
179 		{
180 			mostUsed = i;
181 			mostFired = bulletsFired[i];
182 		}
183 	}
184 
185 	return mostUsed;
186 }
187 
totalUpStats()188 void Game::totalUpStats()
189 {
190 	totalEnemiesDefeated += currentMissionEnemiesDefeated;
191 	totalItemsCollected += currentMissionItemsCollected;
192 
193 	totalSeconds += currentMissionSeconds;
194 	totalMinutes += currentMissionMinutes;
195 	totalHours += currentMissionHours;
196 
197 	while (totalSeconds > 59)
198 	{
199 		totalSeconds -= 60;
200 		totalMinutes++;
201 	}
202 
203 	while (totalMinutes > 59)
204 	{
205 		totalMinutes -= 60;
206 		totalHours++;
207 	}
208 
209 	currentMissionEnemiesDefeated = currentMissionItemsCollected = 0;
210 	currentMissionSeconds = currentMissionMinutes = currentMissionHours = 0;
211 }
212 
setStageName(const char * name)213 void Game::setStageName(const char *name)
214 {
215 	strlcpy(stageName, name, sizeof stageName);
216 }
217 
setMapName(const char * name)218 void Game::setMapName(const char *name)
219 {
220 	strlcpy(mapName, name, sizeof mapName);
221 }
222 
setMissionOver(int reason)223 void Game::setMissionOver(int reason)
224 {
225 	if ((missionOver == 0) || (reason == MIS_TIMEUP))
226 	{
227 		switch (reason)
228 		{
229 			case MIS_COMPLETE:
230 				missionOver = MAX_FPS;
231 				break;
232 			case MIS_PLAYEROUT:
233 				missionOver = (int)(MAX_FPS * 2.5);
234 				break;
235 			case MIS_TIMEUP:
236 			case MIS_PLAYERDEAD:
237 				missionOver = MAX_FPS * 5;
238 				break;
239 			case MIS_PLAYERESCAPE:
240 				missionOver = MAX_FPS * 2;
241 				break;
242 			case MIS_GAMECOMPLETE:
243 				missionOver = MAX_FPS * 8;
244 				break;
245 			default:
246 				missionOver = MAX_FPS;
247 				break;
248 		}
249 	}
250 
251 	missionOverReason = reason;
252 }
253 
resetMissionOver()254 void Game::resetMissionOver()
255 {
256 	missionOver = missionOverReason = 0;
257 }
258