colobot/colobot-base/level/player_profile.h

163 lines
5.2 KiB
C
Raw Normal View History

/*
* This file is part of the Colobot: Gold Edition source code
2023-08-06 21:15:48 +00:00
* Copyright (C) 2001-2023, Daniel Roux, EPSITEC SA & TerranovaTeam
2015-08-22 14:40:02 +00:00
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "graphics/core/color.h"
#include "level/level_category.h"
#include <string>
#include <map>
#include <vector>
struct LevelInfo
{
int numTry = 0;
bool bPassed = false;
};
2022-01-24 18:51:00 +00:00
struct PlayerAppearance
{
int face = 0; // face
int glasses = 0; // glasses
Gfx::Color colorHair; // hair color
Gfx::Color colorCombi; // spacesuit volor
Gfx::Color colorBand; // strips color
void DefPerso();
void DefHairColor();
};
struct SavedScene
{
std::string path;
std::string name;
SavedScene(std::string path = "", std::string name = "")
: path(path), name(name)
{}
};
2015-07-19 13:34:49 +00:00
class CPlayerProfile
{
public:
2015-07-29 16:17:28 +00:00
// Creates CPlayerProfile instance and loads player save data
2015-07-19 13:34:49 +00:00
CPlayerProfile(std::string playerName);
~CPlayerProfile();
2015-07-29 16:17:28 +00:00
// Returns last used player name, or "Player" if none found
static std::string GetLastName();
2015-07-29 16:17:28 +00:00
// Returnslist of possible player names
static std::vector<std::string> GetPlayerList();
2015-07-29 16:17:28 +00:00
// Creates player save directory (if needed)
bool Create();
// Removes player save directory
bool Delete();
2015-07-29 16:17:28 +00:00
//! Returns player name
std::string GetName();
2015-07-29 16:17:28 +00:00
//! Returns player's save directory path
std::string GetSaveDir();
2015-07-29 16:17:28 +00:00
//! Returns path to file inside player's save directory
std::string GetSaveFile(std::string filename);
2015-07-29 16:17:28 +00:00
//! Increments level try count
void IncrementLevelTryCount(LevelCategory cat, int chap, int rank);
2015-07-29 16:17:28 +00:00
//! Returns try count for given level
int GetLevelTryCount(LevelCategory cat, int chap, int rank);
2015-07-29 16:17:28 +00:00
//! Changes level passed status (also updates chapter passed status)
void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed);
2015-07-29 16:17:28 +00:00
//! Chenks if the level (or chapter, if rank=0) is passed
bool GetLevelPassed(LevelCategory cat, int chap, int rank);
2015-07-29 16:17:28 +00:00
//! Returns the highest chapter accessible in the given category
int GetChapPassed(LevelCategory cat);
2015-07-29 16:17:28 +00:00
//! Sets selected chapter for save file
void SetSelectedChap(LevelCategory category, int chap);
2015-07-29 16:17:28 +00:00
//! Returns selected chapter from save file
int GetSelectedChap(LevelCategory category);
2015-07-29 16:17:28 +00:00
//! Sets selected level for save file
void SetSelectedRank(LevelCategory category, int rank);
2015-07-29 16:17:28 +00:00
//! Returns selected level from save file
int GetSelectedRank(LevelCategory category);
2015-07-29 16:17:28 +00:00
//! Returns unlocked EnableBuild for free game
int GetFreeGameBuildUnlock();
2015-07-29 16:17:28 +00:00
//! Saves unlocked EnableBuild for free game
void SetFreeGameBuildUnlock(int freeBuild);
2015-07-29 16:17:28 +00:00
//! Returns unlocked DoneResearch for free game
int GetFreeGameResearchUnlock();
2015-07-29 16:17:28 +00:00
//! Saves unlocked DoneResearch for free game
void SetFreeGameResearchUnlock(int freeResearch);
2022-01-24 18:51:00 +00:00
//! Returns a reference to PlayerAppearance structure
PlayerAppearance& GetAppearance();
//! Loads PlayerAppearance structure
void LoadAppearance();
//! Saves PlayerAppearance structure
void SaveAppearance();
//! Returns true if player has at least one saved scene
bool HasAnySavedScene();
//! Returns list of all saved scenes
std::vector<SavedScene> GetSavedSceneList();
2015-07-29 16:17:28 +00:00
//! Saves current scene status
void SaveScene(std::string dir, std::string info);
//! Loads scene
void LoadScene(std::string dir);
//! Delete saved scene
bool DeleteScene(std::string dir);
protected:
2015-07-29 16:17:28 +00:00
//! Loads LevelInfo data for given category
void LoadFinishedLevels(LevelCategory category);
2015-07-29 16:17:28 +00:00
//! Saves LevelInfo data for given category
void SaveFinishedLevels(LevelCategory category);
2015-07-29 16:17:28 +00:00
//! Loads free game unlock state
void LoadFreeGameUnlock();
2015-07-29 16:17:28 +00:00
//! Saves free game unlock state
void SaveFreeGameUnlock();
protected:
//! Player name
std::string m_playerName;
//! Is finished levels file loaded already?
std::map<LevelCategory, bool> m_levelInfoLoaded;
//! Level completion info
std::map<LevelCategory, std::map<int, std::map<int, LevelInfo>>> m_levelInfo;
//! Selected level chapter
std::map<LevelCategory, int> m_selectChap;
//! Selected level rank
std::map<LevelCategory, int> m_selectRank;
//! Is freegame save file loaded already?
bool m_freegameLoaded;
//! Buildings unlocked for free game
int m_freegameBuild;
//! Researches unlocked for free game
int m_freegameResearch;
2022-01-24 18:51:00 +00:00
//! Player appearance
PlayerAppearance m_appearance;
};