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