1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Simturn duration is now part of StartInfo

This commit is contained in:
Ivan Savenko 2023-09-22 19:57:43 +03:00
parent 3ea807fb8d
commit 5b21a5ffbc
11 changed files with 62 additions and 5 deletions

View File

@ -477,6 +477,13 @@ void CServerHandler::setDifficulty(int to) const
sendLobbyPack(lsd);
}
void CServerHandler::setSimturnsInfo(const SimturnsInfo & info) const
{
LobbySetSimturns pack;
pack.simturnsInfo = info;
sendLobbyPack(pack);
}
void CServerHandler::setTurnTimerInfo(const TurnTimerInfo & info) const
{
LobbySetTurnTime lstt;

View File

@ -66,6 +66,7 @@ public:
virtual void setPlayerOption(ui8 what, int32_t value, PlayerColor player) const = 0;
virtual void setDifficulty(int to) const = 0;
virtual void setTurnTimerInfo(const TurnTimerInfo &) const = 0;
virtual void setSimturnsInfo(const SimturnsInfo &) const = 0;
virtual void sendMessage(const std::string & txt) const = 0;
virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it?
virtual void sendStartGame(bool allowOnlyAI = false) const = 0;
@ -148,6 +149,7 @@ public:
void setPlayerOption(ui8 what, int32_t value, PlayerColor player) const override;
void setDifficulty(int to) const override;
void setTurnTimerInfo(const TurnTimerInfo &) const override;
void setSimturnsInfo(const SimturnsInfo &) const override;
void sendMessage(const std::string & txt) const override;
void sendGuiAction(ui8 action) const override;
void sendRestartGame() const override;

View File

@ -59,6 +59,7 @@ public:
std::shared_ptr<CButton> buttonOptions;
std::shared_ptr<CButton> buttonStart;
std::shared_ptr<CButton> buttonBack;
std::shared_ptr<CButton> buttonSimturns;
std::shared_ptr<SelectionTab> tabSel;
std::shared_ptr<OptionsTab> tabOpt;

View File

@ -158,6 +158,7 @@ public:
virtual void visitLobbySetCampaignBonus(LobbySetCampaignBonus & pack) {}
virtual void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) {}
virtual void visitLobbySetPlayer(LobbySetPlayer & pack) {}
virtual void visitLobbySetSimturns(LobbySetSimturns & pack) {}
virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) {}
virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) {}
virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) {}

View File

@ -750,6 +750,11 @@ void LobbySetPlayer::visitTyped(ICPackVisitor & visitor)
visitor.visitLobbySetPlayer(*this);
}
void LobbySetSimturns::visitTyped(ICPackVisitor & visitor)
{
visitor.visitLobbySetSimturns(*this);
}
void LobbySetTurnTime::visitTyped(ICPackVisitor & visitor)
{
visitor.visitLobbySetTurnTime(*this);

View File

@ -250,6 +250,18 @@ struct DLL_LINKAGE LobbySetPlayer : public CLobbyPackToServer
}
};
struct DLL_LINKAGE LobbySetSimturns : public CLobbyPackToServer
{
SimturnsInfo simturnsInfo;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & simturnsInfo;
}
};
struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
{
TurnTimerInfo turnTimerInfo;

View File

@ -23,6 +23,24 @@ class CMapInfo;
struct PlayerInfo;
class PlayerColor;
struct DLL_LINKAGE SimturnsInfo
{
/// Minimal number of turns that must be played simultaneously even if contact has been detected
int requiredTurns = 0;
/// Maximum number of turns that might be played simultaneously unless contact is detected
int optionalTurns = 0;
/// If set to true, human and 1 AI can act at the same time
bool allowHumanWithAI = false;
template <typename Handler>
void serialize(Handler &h, const int version)
{
h & requiredTurns;
h & optionalTurns;
h & allowHumanWithAI;
}
};
/// Struct which describes the name, the color, the starting bonus of a player
struct DLL_LINKAGE PlayerSettings
{
@ -84,6 +102,7 @@ struct DLL_LINKAGE StartInfo
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
ui32 mapfileChecksum; //0 if not relevant
std::string startTimeIso8601;
SimturnsInfo simturnsInfo;
TurnTimerInfo turnTimerInfo;
std::string mapname; // empty for random map, otherwise name of the map or savegame
bool createRandomMap() const { return mapGenOptions != nullptr; }
@ -108,6 +127,7 @@ struct DLL_LINKAGE StartInfo
h & seedPostInit;
h & mapfileChecksum;
h & startTimeIso8601;
h & simturnsInfo;
h & turnTimerInfo;
h & mapname;
h & mapGenOptions;

View File

@ -399,6 +399,7 @@ void registerTypesLobbyPacks(Serializer &s)
s.template registerType<CLobbyPackToServer, LobbySetCampaignBonus>();
s.template registerType<CLobbyPackToServer, LobbySetPlayer>();
s.template registerType<CLobbyPackToServer, LobbySetTurnTime>();
s.template registerType<CLobbyPackToServer, LobbySetSimturns>();
s.template registerType<CLobbyPackToServer, LobbySetDifficulty>();
s.template registerType<CLobbyPackToServer, LobbyForceSetPlayer>();
}

View File

@ -87,6 +87,7 @@ public:
virtual void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) override;
virtual void visitLobbySetPlayer(LobbySetPlayer & pack) override;
virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) override;
virtual void visitLobbySetSimturns(LobbySetSimturns & pack) override;
virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) override;
virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) override;
};
};

View File

@ -391,6 +391,12 @@ void ApplyOnServerNetPackVisitor::visitLobbySetPlayer(LobbySetPlayer & pack)
result = true;
}
void ApplyOnServerNetPackVisitor::visitLobbySetSimturns(LobbySetSimturns & pack)
{
srv.si->simturnsInfo = pack.simturnsInfo;
result = true;
}
void ApplyOnServerNetPackVisitor::visitLobbySetTurnTime(LobbySetTurnTime & pack)
{
srv.si->turnTimerInfo = pack.turnTimerInfo;

View File

@ -28,14 +28,12 @@ TurnOrderProcessor::TurnOrderProcessor(CGameHandler * owner):
int TurnOrderProcessor::simturnsTurnsMaxLimit() const
{
// TODO
return 28;
return gameHandler->getStartInfo()->simturnsInfo.optionalTurns;
}
int TurnOrderProcessor::simturnsTurnsMinLimit() const
{
// TODO
return 0;
return gameHandler->getStartInfo()->simturnsInfo.requiredTurns;
}
void TurnOrderProcessor::updateContactStatus()
@ -127,6 +125,9 @@ bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerC
if (gameHandler->hasBothPlayersAtSameConnection(active, waiting))
{
if (!gameHandler->getStartInfo()->simturnsInfo.allowHumanWithAI)
return false;
// only one AI and one human can play simultaneoulsy from single connection
if (activeInfo->human == waitingInfo->human)
return false;