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
|
#include "LevelInitialization.h"
#include <algorithm>
#include <cstring>
namespace Jazz2
{
LevelInitialization::LevelInitialization()
: IsLocalSession(true), Difficulty(GameDifficulty::Normal), IsReforged(true), CheatsUsed(false),
LastExitType(ExitType::None), ElapsedMilliseconds(0), PlayerCarryOvers{}
{
}
LevelInitialization::LevelInitialization(StringView level, GameDifficulty difficulty, bool isReforged)
: LevelName(level), IsLocalSession(true), Difficulty(difficulty), IsReforged(isReforged),
CheatsUsed(false), LastExitType(ExitType::None), ElapsedMilliseconds(0), PlayerCarryOvers{}
{
for (std::int32_t i = 0; i < MaxPlayerCount; i++) {
PlayerCarryOvers[i].Type = PlayerType::None;
}
}
LevelInitialization::LevelInitialization(StringView level, GameDifficulty difficulty, bool isReforged, bool cheatsUsed, PlayerType playerType)
: LevelName(level), IsLocalSession(true), Difficulty(difficulty), IsReforged(isReforged),
CheatsUsed(cheatsUsed), LastExitType(ExitType::None), ElapsedMilliseconds(0), PlayerCarryOvers{}
{
PlayerCarryOvers[0].Type = playerType;
PlayerCarryOvers[0].Lives = DefaultLives;
for (std::int32_t i = 1; i < MaxPlayerCount; i++) {
PlayerCarryOvers[i].Type = PlayerType::None;
}
}
LevelInitialization::LevelInitialization(StringView level, GameDifficulty difficulty, bool isReforged, bool cheatsUsed, ArrayView<const PlayerType> playerTypes)
: LevelName(level), IsLocalSession(true), Difficulty(difficulty), IsReforged(isReforged),
CheatsUsed(cheatsUsed), LastExitType(ExitType::None), ElapsedMilliseconds(0), PlayerCarryOvers{}
{
std::int32_t playerCount = std::min((std::int32_t)playerTypes.size(), MaxPlayerCount);
for (std::int32_t i = 0; i < playerCount; i++) {
PlayerCarryOvers[i].Type = playerTypes[i];
PlayerCarryOvers[i].Lives = DefaultLives;
}
for (std::int32_t i = playerCount; i < MaxPlayerCount; i++) {
PlayerCarryOvers[i].Type = PlayerType::None;
}
}
LevelInitialization::LevelInitialization(const LevelInitialization& copy) noexcept
{
LevelName = copy.LevelName;
IsLocalSession = copy.IsLocalSession;
Difficulty = copy.Difficulty;
IsReforged = copy.IsReforged;
CheatsUsed = copy.CheatsUsed;
LastExitType = copy.LastExitType;
LastEpisodeName = copy.LastEpisodeName;
ElapsedMilliseconds = copy.ElapsedMilliseconds;
std::memcpy(PlayerCarryOvers, copy.PlayerCarryOvers, sizeof(PlayerCarryOvers));
}
LevelInitialization::LevelInitialization(LevelInitialization&& move) noexcept
{
LevelName = std::move(move.LevelName);
IsLocalSession = move.IsLocalSession;
Difficulty = move.Difficulty;
IsReforged = move.IsReforged;
CheatsUsed = move.CheatsUsed;
LastExitType = move.LastExitType;
LastEpisodeName = std::move(move.LastEpisodeName);
ElapsedMilliseconds = move.ElapsedMilliseconds;
std::memcpy(PlayerCarryOvers, move.PlayerCarryOvers, sizeof(PlayerCarryOvers));
}
std::int32_t LevelInitialization::GetPlayerCount(const PlayerCarryOver** firstPlayer) const
{
if (firstPlayer != nullptr) {
*firstPlayer = nullptr;
}
std::int32_t playerCount = 0;
for (std::int32_t i = playerCount; i < MaxPlayerCount; i++) {
if (PlayerCarryOvers[i].Type != PlayerType::None) {
playerCount++;
if (firstPlayer != nullptr && *firstPlayer == nullptr) {
*firstPlayer = &PlayerCarryOvers[i];
}
}
}
return playerCount;
}
}
|