1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

netpackages

This commit is contained in:
Laserlicht
2025-10-25 20:41:39 +02:00
parent 678d8275b7
commit 66f377f14e
13 changed files with 90 additions and 28 deletions

View File

@@ -432,6 +432,13 @@ void CServerHandler::setCampaignBonus(int bonusId) const
sendLobbyPack(lscb); sendLobbyPack(lscb);
} }
void CServerHandler::setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const
{
LobbySetBattleOnlyModeStartInfo lsbomsui;
lsbomsui.startInfo = startInfo;
sendLobbyPack(lsbomsui);
}
void CServerHandler::setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts) const void CServerHandler::setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts) const
{ {
LobbySetMap lsm; LobbySetMap lsm;

View File

@@ -15,6 +15,8 @@
#include "../lib/StartInfo.h" #include "../lib/StartInfo.h"
#include "../lib/gameState/GameStatistics.h" #include "../lib/gameState/GameStatistics.h"
#include "lobby/BattleOnlyMode.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class GameConnection; class GameConnection;
@@ -77,6 +79,7 @@ public:
virtual void setCampaignState(std::shared_ptr<CampaignState> newCampaign) = 0; virtual void setCampaignState(std::shared_ptr<CampaignState> newCampaign) = 0;
virtual void setCampaignMap(CampaignScenarioID mapId) const = 0; virtual void setCampaignMap(CampaignScenarioID mapId) const = 0;
virtual void setCampaignBonus(int bonusId) const = 0; virtual void setCampaignBonus(int bonusId) const = 0;
virtual void setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const = 0;
virtual void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const = 0; virtual void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const = 0;
virtual void setPlayer(PlayerColor color) const = 0; virtual void setPlayer(PlayerColor color) const = 0;
virtual void setPlayerName(PlayerColor color, const std::string & name) const = 0; virtual void setPlayerName(PlayerColor color, const std::string & name) const = 0;
@@ -186,6 +189,7 @@ public:
void setCampaignState(std::shared_ptr<CampaignState> newCampaign) override; void setCampaignState(std::shared_ptr<CampaignState> newCampaign) override;
void setCampaignMap(CampaignScenarioID mapId) const override; void setCampaignMap(CampaignScenarioID mapId) const override;
void setCampaignBonus(int bonusId) const override; void setCampaignBonus(int bonusId) const override;
void setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const override;
void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const override; void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const override;
void setPlayer(PlayerColor color) const override; void setPlayer(PlayerColor color) const override;
void setPlayerName(PlayerColor color, const std::string & name) const override; void setPlayerName(PlayerColor color, const std::string & name) const override;

View File

@@ -59,4 +59,5 @@ public:
void visitLobbyLoadProgress(LobbyLoadProgress & pack) override; void visitLobbyLoadProgress(LobbyLoadProgress & pack) override;
void visitLobbyUpdateState(LobbyUpdateState & pack) override; void visitLobbyUpdateState(LobbyUpdateState & pack) override;
void visitLobbyShowMessage(LobbyShowMessage & pack) override; void visitLobbyShowMessage(LobbyShowMessage & pack) override;
void visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack) override;
}; };

View File

@@ -239,3 +239,9 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyShowMessage(LobbyShowMessage &
lobby->buttonStart->block(false); lobby->buttonStart->block(false);
handler.showServerError(pack.message.toString()); handler.showServerError(pack.message.toString());
} }
void ApplyOnLobbyScreenNetPackVisitor::visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack)
{
if(auto topWindow = ENGINE->windows().topWindow<BattleOnlyModeWindow>())
topWindow->applyStartInfo(pack.startInfo);
}

View File

@@ -62,17 +62,6 @@ void BattleOnlyMode::openBattleWindow()
ENGINE->windows().createAndPushWindow<BattleOnlyModeWindow>(); ENGINE->windows().createAndPushWindow<BattleOnlyModeWindow>();
} }
BattleOnlyModeStartInfo::BattleOnlyModeStartInfo()
: selectedTerrain(TerrainId::DIRT)
, selectedTown(FactionID::NONE)
{
for(auto & element : selectedArmy)
element = std::make_shared<CCreatureSet>();
for(auto & element : primSkillLevel)
for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
element[i] = 0;
}
BattleOnlyModeWindow::BattleOnlyModeWindow() BattleOnlyModeWindow::BattleOnlyModeWindow()
: CWindowObject(BORDERED) : CWindowObject(BORDERED)
, startInfo(std::make_shared<BattleOnlyModeStartInfo>()) , startInfo(std::make_shared<BattleOnlyModeStartInfo>())
@@ -191,6 +180,18 @@ void BattleOnlyModeWindow::init()
map->name = MetaString::createFromTextID("vcmi.lobby.battleOnlyMode"); map->name = MetaString::createFromTextID("vcmi.lobby.battleOnlyMode");
cb = std::make_unique<EditorCallback>(map.get()); cb = std::make_unique<EditorCallback>(map.get());
onChange();
}
void BattleOnlyModeWindow::onChange()
{
GAME->server().setBattleOnlyModeStartInfo(startInfo);
}
void BattleOnlyModeWindow::applyStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> si)
{
} }
void BattleOnlyModeWindow::setTerrainButtonText() void BattleOnlyModeWindow::setTerrainButtonText()

View File

@@ -18,6 +18,7 @@ class CGHeroInstance;
class CCreatureSet; class CCreatureSet;
class CMap; class CMap;
class EditorCallback; class EditorCallback;
class BattleOnlyModeStartInfo;
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END
class FilledTexturePlayerColored; class FilledTexturePlayerColored;
@@ -36,20 +37,6 @@ public:
static void openBattleWindow(); static void openBattleWindow();
}; };
class BattleOnlyModeStartInfo
{
public:
TerrainId selectedTerrain;
FactionID selectedTown;
std::array<std::shared_ptr<CGHeroInstance>, 2> selectedHero;
std::array<std::shared_ptr<CCreatureSet>, 2> selectedArmy;
std::array<std::array<int, GameConstants::PRIMARY_SKILLS>, 2> primSkillLevel;
BattleOnlyModeStartInfo();
};
class BattleOnlyModeHeroSelector : public CIntObject class BattleOnlyModeHeroSelector : public CIntObject
{ {
private: private:
@@ -92,9 +79,11 @@ private:
std::shared_ptr<BattleOnlyModeHeroSelector> heroSelector2; std::shared_ptr<BattleOnlyModeHeroSelector> heroSelector2;
void init(); void init();
void onChange();
void setTerrainButtonText(); void setTerrainButtonText();
void setOkButtonEnabled(); void setOkButtonEnabled();
void startBattle(); void startBattle();
public: public:
BattleOnlyModeWindow(); BattleOnlyModeWindow();
void applyStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> si);
}; };

View File

@@ -242,13 +242,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
sortByDate->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("lobby/selectionTabSortDate"))); sortByDate->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("lobby/selectionTabSortDate")));
buttonsSortBy.push_back(sortByDate); buttonsSortBy.push_back(sortByDate);
bool isMultiplayer = GAME->server().loadMode == ELoadMode::MULTI; if(tabType == ESelectionScreen::newGame)
if(tabType == ESelectionScreen::newGame && !isMultiplayer)
{ {
buttonBattleOnlyMode = std::make_shared<CButton>(Point(23, 18), AnimationPath::builtin("lobby/battleButton"), CButton::tooltip("", LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyMode")), [tabTitle, tabTitleDelete](){ buttonBattleOnlyMode = std::make_shared<CButton>(Point(23, 18), AnimationPath::builtin("lobby/battleButton"), CButton::tooltip("", LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyMode")), [tabTitle, tabTitleDelete](){
BattleOnlyMode::openBattleWindow(); BattleOnlyMode::openBattleWindow();
}); });
//buttonBattleOnlyMode->block(GAME->server().isGuest());
} }
if(tabType == ESelectionScreen::loadGame || tabType == ESelectionScreen::newGame) if(tabType == ESelectionScreen::loadGame || tabType == ESelectionScreen::newGame)

View File

@@ -21,6 +21,7 @@
#include "mapping/CMapHeader.h" #include "mapping/CMapHeader.h"
#include "mapping/CMapService.h" #include "mapping/CMapService.h"
#include "modding/ModIncompatibility.h" #include "modding/ModIncompatibility.h"
#include "mapObjects/army/CCreatureSet.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@@ -241,4 +242,15 @@ TeamID LobbyInfo::getPlayerTeamId(const PlayerColor & color)
return TeamID::NO_TEAM; return TeamID::NO_TEAM;
} }
BattleOnlyModeStartInfo::BattleOnlyModeStartInfo()
: selectedTerrain(TerrainId::DIRT)
, selectedTown(FactionID::NONE)
{
for(auto & element : selectedArmy)
element = std::make_shared<CCreatureSet>();
for(auto & element : primSkillLevel)
for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
element[i] = 0;
}
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@@ -25,6 +25,8 @@ VCMI_LIB_NAMESPACE_BEGIN
class CMapGenOptions; class CMapGenOptions;
class CampaignState; class CampaignState;
class CMapInfo; class CMapInfo;
class CGHeroInstance;
class CCreatureSet;
struct PlayerInfo; struct PlayerInfo;
class PlayerColor; class PlayerColor;
@@ -239,5 +241,27 @@ struct DLL_LINKAGE LobbyInfo : public LobbyState
TeamID getPlayerTeamId(const PlayerColor & color); TeamID getPlayerTeamId(const PlayerColor & color);
}; };
class DLL_LINKAGE BattleOnlyModeStartInfo : public Serializeable
{
public:
TerrainId selectedTerrain;
FactionID selectedTown;
std::array<std::shared_ptr<CGHeroInstance>, 2> selectedHero;
std::array<std::shared_ptr<CCreatureSet>, 2> selectedArmy;
std::array<std::array<int, GameConstants::PRIMARY_SKILLS>, 2> primSkillLevel;
BattleOnlyModeStartInfo();
template <typename Handler> void serialize(Handler &h)
{
h & selectedTerrain;
h & selectedTown;
h & selectedHero;
h & selectedArmy;
h & primSkillLevel;
}
};
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@@ -168,6 +168,7 @@ public:
virtual void visitLobbySetCampaign(LobbySetCampaign & pack) {} virtual void visitLobbySetCampaign(LobbySetCampaign & pack) {}
virtual void visitLobbySetCampaignMap(LobbySetCampaignMap & pack) {} virtual void visitLobbySetCampaignMap(LobbySetCampaignMap & pack) {}
virtual void visitLobbySetCampaignBonus(LobbySetCampaignBonus & pack) {} virtual void visitLobbySetCampaignBonus(LobbySetCampaignBonus & pack) {}
virtual void visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack) {}
virtual void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) {} virtual void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) {}
virtual void visitLobbySetPlayer(LobbySetPlayer & pack) {} virtual void visitLobbySetPlayer(LobbySetPlayer & pack) {}
virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) {} virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) {}

View File

@@ -763,6 +763,11 @@ void LobbySetCampaignBonus::visitTyped(ICPackVisitor & visitor)
visitor.visitLobbySetCampaignBonus(*this); visitor.visitLobbySetCampaignBonus(*this);
} }
void LobbySetBattleOnlyModeStartInfo::visitTyped(ICPackVisitor & visitor)
{
visitor.visitLobbySetBattleOnlyModeStartInfo(*this);
}
void LobbyChangePlayerOption::visitTyped(ICPackVisitor & visitor) void LobbyChangePlayerOption::visitTyped(ICPackVisitor & visitor)
{ {
visitor.visitLobbyChangePlayerOption(*this); visitor.visitLobbyChangePlayerOption(*this);

View File

@@ -230,6 +230,18 @@ struct DLL_LINKAGE LobbySetCampaignBonus : public CLobbyPackToServer
} }
}; };
struct DLL_LINKAGE LobbySetBattleOnlyModeStartInfo : public CLobbyPackToPropagate
{
std::shared_ptr<BattleOnlyModeStartInfo> startInfo;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
h & startInfo;
}
};
struct DLL_LINKAGE LobbyChangePlayerOption : public CLobbyPackToServer struct DLL_LINKAGE LobbyChangePlayerOption : public CLobbyPackToServer
{ {
enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS, TOWN_ID, HERO_ID, BONUS_ID}; enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS, TOWN_ID, HERO_ID, BONUS_ID};

View File

@@ -291,6 +291,7 @@ void registerTypes(Serializer &s)
s.template registerType<TimesStackSizeUpdater>(249); s.template registerType<TimesStackSizeUpdater>(249);
s.template registerType<TimesArmySizeUpdater>(250); s.template registerType<TimesArmySizeUpdater>(250);
s.template registerType<PackageReceived>(251); s.template registerType<PackageReceived>(251);
s.template registerType<LobbySetBattleOnlyModeStartInfo>(252);
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END