-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGame.cpp
More file actions
executable file
·690 lines (584 loc) · 18.1 KB
/
Game.cpp
File metadata and controls
executable file
·690 lines (584 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#include "Game.h"
#include <QDebug>
#include <QString>
#include "Defines.h"
#include "Players.h"
Game gameInfo;
Game gameInfoTemp;
Game::Game()
{
qDebug() << "Game::Game() - Constructing.......";
powerSaveMode = true;
fontSize = 28;
GameType = DEFAULT_GAME_TYPE;
GameID = DEFAULT_GAME_ID;
GameLength = DEFAULT_GAME_LENGTH;
NumberOfPlayers = 24;
isReSpawnGame = 0;
isLTARGame = false;
GameName ="LTTO";
NameChar1 = 67; // C
NameChar2 = 85; // U
NameChar3 = 83; // S
NameChar4 = 84; // T
pointsPerTagLanded = POINTS_PER_TAG_LANDED;
pointsPerTagLandedNegative = POINTS_PER_TAG_LANDED_OWN_TEAM;
pointsPerTagTaken = POINTS_PER_HITS_TAKEN;
pointsPerSurvivalMinute = POINTS_PER_SURVIVAL_MINUTE;
pointsPerZoneMinute = POINTS_PER_ZONE_MINUTE;
pointsPerKingHit = POINTS_PER_KING_HIT;
pointsPerKingHitNegative = POINTS_PER_OWN_KING_HIT;
if(gameInfo.getIsSuperSimpleMode() == true)
{
pointsPerTagLandedNegative = 0;
pointsPerSurvivalMinute = 0;
pointsPerZoneMinute = 0;
pointsPerKingHit = 0;
pointsPerKingHitNegative = 0;
}
PlayerToReHost = 0;
isSpiesTeamTagActive = false;
team1rank = 0;
team2rank = 0;
team3rank = 0;
#ifdef QT_DEBUG
CountDownTime = DEBUG_COUNTDOWN_TIME;
#else
CountDownTime = DEFAULT_COUNTDOWN_TIME;
#endif
isThisPlayerInTheGame[0] = true; //this is required so that Announce continues after all Taggers are hosted.
for (int index= 1; index <= MAX_PLAYERS; index++)
{
isThisPlayerInTheGame[index] = false;
}
for (int index = 1; index < 3; index++)
{
PlayersInTeamByte[index] = 0;
}
}
int Game::getGameType() const
{
return GameType;
}
void Game::setGameType(int value)
{
GameType = value;
for(int index = 0; index < 25; index++)
{
// Reset Game Specific Flags and buttons.
playerInfo[index].setBitFlags1(NEUTRALISE_10_FLAG, false);
playerInfo[index].setBitFlags1(HUNT_THE_PREY_FLAG, false);
playerInfo[index].setBitFlags1(REVERSE_HUNT_DIR_FLAG, false);
playerInfo[index].setBitFlags2(CONTESTED_ZONES_FLAG, false);
playerInfo[index].setBitFlags2(NEUTRALISE_15s_TAGGED_FLAG, false);
playerInfo[index].setBitFlags2(ZONES_TO_TEAMS_FLAG, false);
playerInfo[index].setBitFlags2(SUPPLY_ZONES_REVIVE_FLAG, false);
playerInfo[index].setBitFlags2(SUPPLY_ZONES_REFILL_TAGS_FLAG, false);
playerInfo[index].setBitFlags2(HOSTILE_ZONES_FLAG, false);
// Set Game Specific Flags and Number of Teams Flags
switch(value)
{
case Ltag0:
setNumberOfTeams(0);
break;
case Ltag2:
setNumberOfTeams(2);
break;
case Ltag3:
setNumberOfTeams(3);
break;
case HideSeek2:
playerInfo[index].setBitFlags1(HUNT_THE_PREY_FLAG, true);
setNumberOfTeams(2);
break;
case HideSeek3:
playerInfo[index].setBitFlags1(HUNT_THE_PREY_FLAG, true);
setNumberOfTeams(3);
break;
case Kings2:
setNumberOfTeams(2);
break;
case Kings3:
setNumberOfTeams(3);
break;
case OwnZone0:
playerInfo[index].setBitFlags2(NEUTRALISE_15s_TAGGED_FLAG, true);
playerInfo[index].setBitFlags2(CONTESTED_ZONES_FLAG, true);
setNumberOfTeams(0);
break;
case OwnZone2:
playerInfo[index].setBitFlags2(NEUTRALISE_15s_TAGGED_FLAG, true);
playerInfo[index].setBitFlags2(CONTESTED_ZONES_FLAG, true);
setNumberOfTeams(2);
break;
case OwnZone3:
playerInfo[index].setBitFlags2(CONTESTED_ZONES_FLAG, true);
setNumberOfTeams(3);
break;
case Custom:
// Nothing to do here.
break;
case LtarGame:
setIsLTARGame(true);
}
}
}
int Game::getGameID() const
{
return GameID;
}
void Game::setGameID(int value)
{
GameID = value;
}
int Game::getGameLength() const
{
return GameLength;
}
void Game::setGameLength(int value)
{
GameLength = value;
}
int Game::getNumberOfPlayers() const
{
return NumberOfPlayers;
}
void Game::setNumberOfPlayers(int value)
{
NumberOfPlayers = value;
}
int Game::getNumberOfTeams() const
{
return NumberOfTeams;
}
void Game::setNumberOfTeams(int value)
{
NumberOfTeams = value;
//now set the Flags2 Team bits
bool msb, lsb;
switch (value)
{
case 0:
msb = 0;
lsb = 1;
break;
case 1:
msb = 0;
lsb = 1;
break;
case 2:
msb = 1;
lsb = 0;
break;
case 3:
msb = 1;
lsb = 1;
break;
default:
msb = 0;
lsb = 0;
}
for(int x = 0; x < 25; x++)
{
playerInfo[x].setBitFlags2(TEAM_COUNT_MSB, msb);
playerInfo[x].setBitFlags2(TEAM_COUNT_LSB, lsb);
}
}
int Game::getNumberOfSpies() const
{
return NumberOfSpies;
}
void Game::setNumberOfSpies(int value)
{
NumberOfSpies = value;
}
QString Game::getGameName() const
{
return GameName;
}
void Game::setGameName(QString value)
{
GameName = value;
qInfo() << "Game::setGameName() -" << value;
}
bool Game::getIsThisPlayerInTheGame(int index) const
{
return isThisPlayerInTheGame[index];
}
void Game::setIsThisPlayerInTheGame(int index, int value)
{
isThisPlayerInTheGame[index] = value;
}
int Game::getPlayersInTeam(int TeamNumber) const
{
//TODO: This is BROKEN. Please fix it!
int retVal = 0;
if (gameInfo.getIsLTARGame())
{
qDebug() << "Game::getPlayersInTeam() - LTAR Mode - PlayersInTeamByte =" << PlayersInTeamByte[TeamNumber];
//retVal = PlayersInTeamByte[TeamNumber];
retVal = 255;
}
else
{
int numberOfPlayersInThisTeam = 0;
Q_UNUSED(numberOfPlayersInThisTeam);
int startingPlayer = 1 + (8*(TeamNumber-1));
int endingPlayer = 1+(8*TeamNumber);
for (int index = startingPlayer; index < endingPlayer; index++)
{
if (gameInfo.getIsThisPlayerInTheGame(index) == true) numberOfPlayersInThisTeam++;
}
//qDebug() << "Game::getPlayersInTeam() - Number of players =" << numberOfPlayersInThisTeam << "in Team" << TeamNumber;
//retVal = numberOfPlayersInThisTeam;
retVal = 8;
}
return retVal;
}
void Game::setPlayersInTeamByte(int TeamNumber, int PlayerNumber, bool state)
{
//This is wrong. Just needs to be a sum of the number of players in the team.
//Except maybe in an LTar
PlayersInTeamByte[TeamNumber] ^= (-state ^ PlayersInTeamByte[TeamNumber]) & (1 << (PlayerNumber-1));
}
////////////////////////////////////////////////////////////////////////////////////
void Game::streamToFile(QTextStream &out)
{
out << "GameID:" << GameID << Qt::endl;
out << "GameLength:" << GameLength << Qt::endl;
out << "GameName:" << GameName << Qt::endl;
out << "GameType:" << GameType << Qt::endl;
out << "NumberOfPlayers:" << NumberOfPlayers << Qt::endl;
out << "NumberOfTeams:" << NumberOfTeams << Qt::endl;
out << "NumberOfSpies:" << NumberOfSpies << Qt::endl;
out << "CountDownTime:" << CountDownTime << Qt::endl;
out << "SpyTeamTagsActive:" << isSpiesTeamTagActive << Qt::endl;
out << "LTARmode:" << isLTARGame << Qt::endl;
out << "ReSpawnEnabled:" << isReSpawnGame << Qt::endl;
out << "CumulativeScores:" << cumulativeScoreMode << Qt::endl;
out << "PointsPerTagLanded:" << pointsPerTagLanded << Qt::endl;
out << "PointsPerTagLandedNegative:" << pointsPerTagLandedNegative << Qt::endl;
out << "PointsPerTagTaken:" << pointsPerTagTaken << Qt::endl;
out << "PointsPerSurvivalMinute:" << pointsPerSurvivalMinute << Qt::endl;
out << "PointsPerZoneMinute:" << pointsPerZoneMinute << Qt::endl;
out << "PointsPerKingHit:" << pointsPerKingHit << Qt::endl;
out << "PointsPermingHitNegative:" << pointsPerKingHitNegative << Qt::endl;
for (int x=0; x< 25; x++)
{
if (x < 10) out << " Player0" << x << ":" << isThisPlayerInTheGame[x] << Qt::endl;
else out << " Player" << x << ":" << isThisPlayerInTheGame[x] << Qt::endl;;
}
out << "END_OF_GAME_SETTINGS" << Qt::endl;
// qDebug() << "GameID:" << GameID;
// qDebug() << "GameLength:" << GameLength;
// qDebug() << "GameName:" << GameName;
// qDebug() << "GameType:" << GameType;
// qDebug() << "NumberOfPlayers:" << NumberOfPlayers;
// qDebug() << "NumberOfTeams:" << NumberOfTeams;
// qDebug() << "NumberOfSpies:" << NumberOfSpies;
// qDebug() << "CountDownTime" << CountDownTime;
// qDebug() << "SpyTeamTagsActive" << isSpiesTeamTagActive;
// qDebug() << "LTARmode" << isLTARGame;
// qDebug() << "ReSpawnEnabled" << isReSpawnGame;
qDebug() << "Game::StreamToFile has left the building";
}
void Game::streamFromFile(QTextStream &in)
{
QString descriptorG;
do
{
descriptorG = in.readLine();
//qDebug() << descriptorG << descriptorG.indexOf(":");
if (descriptorG.contains("GameID:") ) GameID = extractInteger(descriptorG);
else if (descriptorG.contains("GameLength:") ) GameLength = extractInteger(descriptorG);
else if (descriptorG.contains("GameType:") ) GameType = extractInteger(descriptorG);
else if (descriptorG.contains("NumberOfPlayers:") ) NumberOfPlayers = extractInteger(descriptorG);
else if (descriptorG.contains("NumberOfTeams:") ) NumberOfTeams = extractInteger(descriptorG);
else if (descriptorG.contains("NumberOfSpies:") ) NumberOfSpies = extractInteger(descriptorG);
else if (descriptorG.contains("GameName:") ) GameName = descriptorG;
else if (descriptorG.contains(" Player") ) isThisPlayerInTheGame[descriptorG.mid(7,2).toInt()] = descriptorG.right(1).toInt();
else if (descriptorG.contains("CountDownTime:") ) CountDownTime = extractInteger(descriptorG);
else if (descriptorG.contains("SpyTeamTagsActive:") ) isSpiesTeamTagActive = extractInteger(descriptorG);
else if (descriptorG.contains("LTARmode:") ) isLTARGame = extractInteger(descriptorG);
else if (descriptorG.contains("ReSpawnEnabled:") ) isReSpawnGame = extractInteger(descriptorG);
else if (descriptorG.contains("CumulativeScores:") ) cumulativeScoreMode = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerTagLanded:") ) pointsPerTagLanded = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerTagLandedNegative:") ) pointsPerTagLandedNegative = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerTagTaken:") ) pointsPerTagTaken = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerSurvivalMinute:") ) pointsPerSurvivalMinute = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerZoneMinute:") ) pointsPerZoneMinute = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPerKingHit:") ) pointsPerKingHit = extractInteger(descriptorG);
else if (descriptorG.contains("PointsPermingHitNegative:") ) pointsPerKingHitNegative = extractInteger(descriptorG);
} while (descriptorG != "END_OF_GAME_SETTINGS");
setNumberOfTeams(NumberOfTeams); //This is required to update the Flags2 bits.
// qDebug() << "GameID:" << GameID;
// qDebug() << "GameLength:" << GameLength;
// qDebug() << "GameName:" << GameName;
// qDebug() << "GameType:" << GameType;
// qDebug() << "NumberOfPlayers:" << NumberOfPlayers;
// qDebug() << "NumberOfTeams:" << NumberOfTeams;
// qDebug() << "NumberOfSpies:" << NumberOfSpies;
// qDebug() << "CountDownTime" << CountDownTime;
// qDebug() << "SpyTeamTagsActive" << isSpiesTeamTagActive;
// qDebug() << "LTARmode" << isLTARGame;
// qDebug() << "ReSpawnEnabled" << isReSpawnGame;
// qDebug() << "PlayersInGame;";
// for (int x=0; x< 25; x++)
// {
// qDebug() << " Player" << x << ":" << isThisPlayerInTheGame[x];
// }
// qDebug() << "Game::StreamFromFile has left the building" << endl;
}
int Game::getCountDownTime() const
{
return CountDownTime;
}
void Game::setCountDownTime(int value)
{
CountDownTime = value;
}
char Game::getNameChar1() const
{
return NameChar1;
}
void Game::setNameChar1(char value)
{
NameChar1 = value;
}
char Game::getNameChar2() const
{
return NameChar2;
}
void Game::setNameChar2(char value)
{
NameChar2 = value;
}
char Game::getNameChar3() const
{
return NameChar3;
}
void Game::setNameChar3(char value)
{
NameChar3 = value;
}
char Game::getNameChar4() const
{
return NameChar4;
}
void Game::setNameChar4(char value)
{
NameChar4 = value;
}
bool Game::getIsSpiesTeamTagActive() const
{
return isSpiesTeamTagActive;
}
void Game::setIsSpiesTeamTagActive(bool value)
{
isSpiesTeamTagActive = value;
}
int Game::getTotalNumberOfPlayersInGame() const
{
int count = 0;
for (int x = 1; x<25;x++)
{
if(getIsThisPlayerInTheGame(x)) count++;
}
return count;
}
int Game::getPlayerToReHost() const
{
return PlayerToReHost;
}
void Game::setPlayerToReHost(int value)
{
PlayerToReHost = value;
}
bool Game::getIsLTARGame() const
{
return isLTARGame;
}
void Game::setIsLTARGame(bool value)
{
isLTARGame = value;
}
int Game::getIsReSpawnGame() const
{
return isReSpawnGame;
}
void Game::setIsReSpawnGame(int value)
{
isReSpawnGame = value;
}
int Game::getNumberOfPlayersInGame()
{
numberOfPlayersInGame = 0;
for (int index = 1; index < 25; index++)
{
if(isThisPlayerInTheGame[index] == true) numberOfPlayersInGame++;
}
return numberOfPlayersInGame;
}
int Game::getPointsPerTagLanded() const
{
return pointsPerTagLanded;
}
void Game::setPointsPerTagLanded(int value)
{
pointsPerTagLanded = value;
}
int Game::getPointsPerTagLandedNegative() const
{
return pointsPerTagLandedNegative;
}
void Game::setPointsPerTagLandedNegative(int value)
{
pointsPerTagLandedNegative = value;
}
int Game::getPointsPerTagTaken() const
{
return pointsPerTagTaken;
}
void Game::setPointsPerTagTaken(int value)
{
pointsPerTagTaken = value;
}
int Game::getPointsPerKingHit() const
{
return pointsPerKingHit;
}
void Game::setPointsPerKingHit(int value)
{
pointsPerKingHit = value;
}
int Game::getPointsPerKingHitNegative() const
{
return pointsPerKingHitNegative;
}
void Game::setPointsPerKingHitNegative(int value)
{
pointsPerKingHitNegative = value;
}
int Game::getPointsPerSurvivalMinute() const
{
return pointsPerSurvivalMinute;
}
void Game::setPointsPerSurvivalMinute(int value)
{
pointsPerSurvivalMinute = value;
}
int Game::getPointsPerZoneMinute() const
{
return pointsPerZoneMinute;
}
void Game::setPointsPerZoneMinute(int value)
{
pointsPerZoneMinute = value;
}
int Game::getTeam1rank() const
{
return team1rank;
}
void Game::setTeam1rank(int value)
{
team1rank = value;
}
int Game::getTeam2rank() const
{
return team2rank;
}
void Game::setTeam2rank(int value)
{
team2rank = value;
}
int Game::getTeam3rank() const
{
return team3rank;
}
void Game::setTeam3rank(int value)
{
team3rank = value;
}
bool Game::getIsIndoorViewMode() const
{
return isIndoorViewMode;
}
void Game::setIsIndoorViewMode(bool value)
{
isIndoorViewMode = value;
}
bool Game::getCumulativeScoreMode() const
{
return cumulativeScoreMode;
}
void Game::setCumulativeScoreMode(bool value)
{
cumulativeScoreMode = value;
}
bool Game::getPowerSaveMode() const
{
return powerSaveMode;
}
void Game::setPowerSaveMode(bool value)
{
powerSaveMode = value;
}
int Game::getFontSize()
{
return fontSize;
}
void Game::setFontSize(int value)
{
if (value == 0)
{
value = DEFAULT_FONT_SIZE;
qWarning() << "setFontSize.value == 0 OVERIDE =" << DEFAULT_FONT_SIZE;
}
fontSize = value;
}
QString Game::getCurrentGameFileName() const
{
return currentGameFileName;
}
void Game::setCurrentGameFileName(const QString &value)
{
currentGameFileName = value;
}
int Game::getScoreHeaderFontSize() const
{
return scoreHeaderFontSize;
}
void Game::setScoreHeaderFontSize(int value)
{
if (value <= 0)
{
value = DEFAULT_FONT_SIZE;
qWarning() << "setScoreHeaderFontSize.value == 0 OVERIDE =" << DEFAULT_FONT_SIZE;
}
scoreHeaderFontSize = value;
}
int Game::getScoreTableFontSize() const
{
return scoreTableFontSize;
}
void Game::setScoreTableFontSize(int value)
{
if (value <= 0)
{
value = DEFAULT_FONT_SIZE;
qWarning() << "setScoreTableFontSize.value == 0 OVERIDE =" << DEFAULT_FONT_SIZE;
}
scoreTableFontSize = value;
}
bool Game::getIsSuperSimpleMode() const
{
return superSimpleMode;
}
void Game::setIsSuperSimpleMode(bool value)
{
superSimpleMode = value;
}
int Game::extractInteger(QString &dG)
{
return dG.right((dG.length() - (dG.indexOf(":")+1) )).toInt(); //extracts all the chars to right of the ":" and convert to an Int
}