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"
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2013-04-15 20:18:04 +03:00
|
|
|
class CMapGenOptions;
|
2012-09-18 20:47:52 +03:00
|
|
|
class CCampaignState;
|
2018-01-05 19:21:07 +02:00
|
|
|
class CMapInfo;
|
|
|
|
struct PlayerInfo;
|
|
|
|
class PlayerColor;
|
|
|
|
class SharedMemory;
|
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;
|
2012-12-02 15:21:44 +03:00
|
|
|
si16 castle;
|
|
|
|
si32 hero,
|
2015-12-05 01:40:23 +02:00
|
|
|
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
|
2013-03-03 20:06:03 +03:00
|
|
|
TeamID team;
|
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;
|
2018-01-05 19:21:07 +02:00
|
|
|
if(version < 787)
|
|
|
|
{
|
|
|
|
ui8 oldConnectedId = 0;
|
|
|
|
h & oldConnectedId;
|
|
|
|
if(oldConnectedId)
|
|
|
|
{
|
|
|
|
connectedPlayerIDs.insert(oldConnectedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h & connectedPlayerIDs;
|
|
|
|
}
|
2012-01-19 17:33:22 +03:00
|
|
|
h & team;
|
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
|
|
|
|
|
|
|
|
typedef std::map<PlayerColor, PlayerSettings> TPlayerInfos;
|
|
|
|
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
|
2013-05-21 22:08:06 +03:00
|
|
|
bool createRandomMap() const { return mapGenOptions.get() != nullptr; }
|
2015-12-29 04:43:33 +02:00
|
|
|
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
2012-09-21 20:59:54 +03:00
|
|
|
|
2015-12-29 04:43:33 +02:00
|
|
|
std::shared_ptr<CCampaignState> campState;
|
2012-09-21 20:59:54 +03:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
PlayerSettings & getIthPlayersSettings(PlayerColor no);
|
|
|
|
const PlayerSettings & getIthPlayersSettings(PlayerColor no) const;
|
|
|
|
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
|
|
|
|
2012-11-20 20:53:45 +03:00
|
|
|
StartInfo() : mode(INVALID), difficulty(0), 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LobbyState
|
|
|
|
{
|
|
|
|
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
|
|
|
|
int campaignMap;
|
|
|
|
int campaignBonus;
|
|
|
|
|
|
|
|
LobbyState() : si(new StartInfo()), hostClientId(-1), campaignMap(-1), campaignBonus(-1) {}
|
|
|
|
|
|
|
|
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;
|
|
|
|
std::shared_ptr<SharedMemory> shm;
|
|
|
|
|
|
|
|
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;
|
|
|
|
bool isClientColor(int clientId, PlayerColor color) const;
|
|
|
|
ui8 clientFirstId(int clientId) const; // Used by chat only!
|
|
|
|
PlayerInfo & getPlayerInfo(int color);
|
|
|
|
TeamID getPlayerTeamId(PlayerColor color);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExceptionMapMissing : public std::exception {};
|
|
|
|
class ExceptionNoHuman : public std::exception {};
|
|
|
|
class ExceptionNoTemplate : public std::exception {};
|