2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* StartInfo.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GameConstants.h"
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "campaign/CampaignConstants.h"
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-04-15 20:18:04 +03:00
|
|
|
class CMapGenOptions;
|
2023-06-25 20:16:03 +02:00
|
|
|
class CampaignState;
|
2018-01-05 19:21:07 +02:00
|
|
|
class CMapInfo;
|
|
|
|
struct PlayerInfo;
|
|
|
|
class PlayerColor;
|
2012-09-18 20:47:52 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Struct which describes the name, the color, the starting bonus of a player
|
2018-01-05 19:21:07 +02:00
|
|
|
struct DLL_LINKAGE PlayerSettings
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-12-02 15:21:44 +03:00
|
|
|
enum { PLAYER_AI = 0 }; // for use in playerID
|
|
|
|
|
|
|
|
enum Ebonus {
|
|
|
|
NONE = -2,
|
|
|
|
RANDOM = -1,
|
|
|
|
ARTIFACT = 0,
|
|
|
|
GOLD = 1,
|
|
|
|
RESOURCE = 2
|
|
|
|
};
|
|
|
|
|
2013-02-02 01:04:25 +03:00
|
|
|
Ebonus bonus;
|
2023-07-11 14:16:02 +02:00
|
|
|
FactionID castle;
|
|
|
|
HeroTypeID hero;
|
|
|
|
HeroTypeID heroPortrait; //-1 if default, else ID
|
2010-07-31 16:55:05 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
std::string heroName;
|
2017-08-11 19:03:05 +02:00
|
|
|
PlayerColor color; //from 0 -
|
2013-02-02 01:04:25 +03:00
|
|
|
enum EHandicap {NO_HANDICAP, MILD, SEVERE};
|
|
|
|
EHandicap handicap;//0-no, 1-mild, 2-severe
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
std::string name;
|
2018-01-05 19:21:07 +02:00
|
|
|
std::set<ui8> connectedPlayerIDs; //Empty - AI, or connectrd player ids
|
2013-01-06 22:30:12 +03:00
|
|
|
bool compOnly; //true if this player is a computer only player; required for RMG
|
2012-12-02 15:21:44 +03:00
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler &h, const int version)
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
h & castle;
|
|
|
|
h & hero;
|
|
|
|
h & heroPortrait;
|
|
|
|
h & heroName;
|
|
|
|
h & bonus;
|
|
|
|
h & color;
|
|
|
|
h & handicap;
|
|
|
|
h & name;
|
2022-06-20 16:39:50 +02:00
|
|
|
h & connectedPlayerIDs;
|
2013-01-06 22:30:12 +03:00
|
|
|
h & compOnly;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
PlayerSettings();
|
|
|
|
bool isControlledByAI() const;
|
|
|
|
bool isControlledByHuman() const;
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Struct which describes the difficulty, the turn time,.. of a heroes match.
|
2018-01-05 19:21:07 +02:00
|
|
|
struct DLL_LINKAGE StartInfo
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2017-07-01 15:30:13 +02:00
|
|
|
enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, INVALID = 255};
|
2010-08-18 12:50:25 +03:00
|
|
|
|
2015-12-05 01:40:23 +02:00
|
|
|
EMode mode;
|
|
|
|
ui8 difficulty; //0=easy; 4=impossible
|
|
|
|
|
2023-04-17 23:11:16 +02:00
|
|
|
using TPlayerInfos = std::map<PlayerColor, PlayerSettings>;
|
2015-12-05 01:40:23 +02:00
|
|
|
TPlayerInfos playerInfos; //color indexed
|
|
|
|
|
|
|
|
ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
|
2012-04-14 05:20:22 +03:00
|
|
|
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
|
|
|
|
ui32 mapfileChecksum; //0 if not relevant
|
2009-04-16 14:14:13 +03:00
|
|
|
ui8 turnTime; //in minutes, 0=unlimited
|
2012-11-20 20:53:45 +03:00
|
|
|
std::string mapname; // empty for random map, otherwise name of the map or savegame
|
2023-04-17 23:11:16 +02:00
|
|
|
bool createRandomMap() const { return mapGenOptions != nullptr; }
|
2015-12-29 04:43:33 +02:00
|
|
|
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
2012-09-21 20:59:54 +03:00
|
|
|
|
2023-06-25 20:16:03 +02:00
|
|
|
std::shared_ptr<CampaignState> campState;
|
2012-09-21 20:59:54 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
PlayerSettings & getIthPlayersSettings(const PlayerColor & no);
|
|
|
|
const PlayerSettings & getIthPlayersSettings(const PlayerColor & no) const;
|
2018-01-05 19:21:07 +02:00
|
|
|
PlayerSettings * getPlayersSettings(const ui8 connectedPlayerId);
|
2010-02-16 18:35:24 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
// TODO: Must be client-side
|
|
|
|
std::string getCampaignName() const;
|
2010-02-16 18:35:24 +02:00
|
|
|
|
2012-12-02 15:21:44 +03:00
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler &h, const int version)
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
h & mode;
|
|
|
|
h & difficulty;
|
|
|
|
h & playerInfos;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & seedToBeUsed;
|
|
|
|
h & seedPostInit;
|
2012-04-14 05:20:22 +03:00
|
|
|
h & mapfileChecksum;
|
2009-04-16 14:14:13 +03:00
|
|
|
h & turnTime;
|
|
|
|
h & mapname;
|
2012-11-20 20:53:45 +03:00
|
|
|
h & mapGenOptions;
|
2012-09-21 20:59:54 +03:00
|
|
|
h & campState;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2023-04-13 18:06:17 +02:00
|
|
|
StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0),
|
2013-05-21 22:08:06 +03:00
|
|
|
mapfileChecksum(0), turnTime(0)
|
2010-10-24 14:35:14 +03:00
|
|
|
{
|
2012-11-20 20:53:45 +03:00
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
struct ClientPlayer
|
|
|
|
{
|
|
|
|
int connection;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & connection;
|
|
|
|
h & name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-19 12:52:02 +02:00
|
|
|
struct DLL_LINKAGE LobbyState
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<StartInfo> si;
|
|
|
|
std::shared_ptr<CMapInfo> mi;
|
|
|
|
std::map<ui8, ClientPlayer> playerNames; // id of player <-> player name; 0 is reserved as ID of AI "players"
|
|
|
|
int hostClientId;
|
|
|
|
// TODO: Campaign-only and we don't really need either of them.
|
|
|
|
// Before start both go into CCampaignState that is part of StartInfo
|
2023-06-25 20:16:03 +02:00
|
|
|
CampaignScenarioID campaignMap;
|
2018-01-05 19:21:07 +02:00
|
|
|
int campaignBonus;
|
|
|
|
|
2023-06-25 20:16:03 +02:00
|
|
|
LobbyState() : si(new StartInfo()), hostClientId(-1), campaignMap(CampaignScenarioID::NONE), campaignBonus(-1) {}
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & si;
|
|
|
|
h & mi;
|
|
|
|
h & playerNames;
|
|
|
|
h & hostClientId;
|
|
|
|
h & campaignMap;
|
|
|
|
h & campaignBonus;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE LobbyInfo : public LobbyState
|
|
|
|
{
|
|
|
|
boost::mutex stateMutex;
|
|
|
|
std::string uuid;
|
|
|
|
|
|
|
|
LobbyInfo() {}
|
|
|
|
|
|
|
|
void verifyStateBeforeStart(bool ignoreNoHuman = false) const;
|
|
|
|
|
|
|
|
bool isClientHost(int clientId) const;
|
|
|
|
std::set<PlayerColor> getAllClientPlayers(int clientId);
|
|
|
|
std::vector<ui8> getConnectedPlayerIdsForClient(int clientId) const;
|
|
|
|
|
|
|
|
// Helpers for lobby state access
|
|
|
|
std::set<PlayerColor> clientHumanColors(int clientId);
|
|
|
|
PlayerColor clientFirstColor(int clientId) const;
|
2023-03-13 23:26:44 +02:00
|
|
|
bool isClientColor(int clientId, const PlayerColor & color) const;
|
2018-01-05 19:21:07 +02:00
|
|
|
ui8 clientFirstId(int clientId) const; // Used by chat only!
|
|
|
|
PlayerInfo & getPlayerInfo(int color);
|
2023-03-13 23:26:44 +02:00
|
|
|
TeamID getPlayerTeamId(const PlayerColor & color);
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|