Skip to content

Commit

Permalink
Add new parameter lua_path to HostGame api
Browse files Browse the repository at this point in the history
  • Loading branch information
ottml authored and Flow86 committed Nov 6, 2023
1 parent 4f496db commit 04b1a1b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 10 deletions.
5 changes: 3 additions & 2 deletions libs/s25main/QuickStartGame.cpp
Expand Up @@ -87,8 +87,9 @@ bool QuickStartGame(const boost::filesystem::path& mapOrReplayPath, const std::v

WINDOWMANAGER.Switch(std::make_unique<dskSelectMap>(csi));

if((extension == ".sav" && GAMECLIENT.HostGame(csi, mapOrReplayPath, MapType::Savegame))
|| ((extension == ".swd" || extension == ".wld") && GAMECLIENT.HostGame(csi, mapOrReplayPath, MapType::OldMap)))
if((extension == ".sav" && GAMECLIENT.HostGame(csi, {mapOrReplayPath, MapType::Savegame}))
|| ((extension == ".swd" || extension == ".wld")
&& GAMECLIENT.HostGame(csi, {mapOrReplayPath, MapType::OldMap})))
{
GAMECLIENT.SetAIBattlePlayers(std::move(aiInfos));
WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwConnecting>(csi.type, nullptr));
Expand Down
5 changes: 3 additions & 2 deletions libs/s25main/desktops/dskCampaignMissionSelection.cpp
Expand Up @@ -121,10 +121,11 @@ void dskCampaignMissionSelection::UpdateMissionPage()
}
}

void dskCampaignMissionSelection::StartServer(const boost::filesystem::path& mapPath)
void dskCampaignMissionSelection::StartServer(const boost::filesystem::path& mapPath,
const boost::optional<boost::filesystem::path>& luaPath)
{
// Start server
if(!GAMECLIENT.HostGame(csi_, mapPath, MapType::OldMap))
if(!GAMECLIENT.HostGame(csi_, {mapPath, MapType::OldMap, luaPath}))
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), _("Hosting of game not possible"), this,
MsgboxButton::Ok, MsgboxIcon::ExclamationRed, ID_msgBoxError));
Expand Down
3 changes: 2 additions & 1 deletion libs/s25main/desktops/dskCampaignMissionSelection.h
Expand Up @@ -7,6 +7,7 @@
#include "desktops/Desktop.h"
#include "network/CreateServerInfo.h"
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/signals2/connection.hpp>

struct CampaignDescription;
Expand All @@ -20,7 +21,7 @@ class dskCampaignMissionSelection : public Desktop
void UpdateMissionPage();
void Msg_ButtonClick(unsigned ctrl_id) override;
void Msg_Group_ButtonClick(unsigned group_id, unsigned ctrl_id) override;
void StartServer(const boost::filesystem::path& mapPath);
void StartServer(const boost::filesystem::path& mapPath, const boost::optional<boost::filesystem::path>& luaPath);
void UpdateEnabledStateOfNextPreviousButton();
boost::filesystem::path campaignFolder_;
CreateServerInfo csi_;
Expand Down
3 changes: 2 additions & 1 deletion libs/s25main/desktops/dskCampaignSelection.cpp
Expand Up @@ -169,7 +169,8 @@ void dskCampaignSelection::Msg_Timer(unsigned ctrl_id)
void dskCampaignSelection::FillCampaignsTable()
{
const size_t numFaultyCampaignsPrior = brokenCampaignPaths_.size();
static const std::array<std::string, 2> campaignFolders = {{s25::folders::campaignsBuiltin, s25::folders::campaignsUser}};
static const std::array<std::string, 2> campaignFolders = {
{s25::folders::campaignsBuiltin, s25::folders::campaignsUser}};

auto* table = GetCtrl<ctrlTable>(ID_Table);
for(const auto& campaignFolder : campaignFolders)
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/desktops/dskSelectMap.cpp
Expand Up @@ -350,7 +350,7 @@ void dskSelectMap::StartServer()
const std::string& mapPath = table->GetItemText(*selection, 5);

// Server starten
if(!GAMECLIENT.HostGame(csi, mapPath, MapType::OldMap))
if(!GAMECLIENT.HostGame(csi, {mapPath, MapType::OldMap}))
GoBack();
else
{
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/desktops/dskSinglePlayer.cpp
Expand Up @@ -88,7 +88,7 @@ void dskSinglePlayer::Msg_ButtonClick(const unsigned ctrl_id)

WINDOWMANAGER.Switch(std::make_unique<dskSelectMap>(csi));

if(GAMECLIENT.HostGame(csi, mostRecentFilepath, MapType::Savegame))
if(GAMECLIENT.HostGame(csi, {mostRecentFilepath, MapType::Savegame}))
WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwConnecting>(csi.type, nullptr));
else
{
Expand Down
10 changes: 10 additions & 0 deletions libs/s25main/gameTypes/MapDescription.cpp
@@ -0,0 +1,10 @@
// Copyright (C) 2005 - 2023 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#include "MapDescription.h"

MapDescription::MapDescription(boost::filesystem::path map_path, MapType map_type,
boost::optional<boost::filesystem::path> lua_path)
: map_path(std::move(map_path)), map_type(map_type), lua_path(std::move(lua_path))
{}
19 changes: 19 additions & 0 deletions libs/s25main/gameTypes/MapDescription.h
@@ -0,0 +1,19 @@
// Copyright (C) 2005 - 2023 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "gameTypes/MapType.h"
#include <boost/filesystem/path.hpp>
#include <boost/optional.hpp>

struct MapDescription
{
boost::filesystem::path map_path;
MapType map_type;
boost::optional<boost::filesystem::path> lua_path;

MapDescription(boost::filesystem::path map_path, MapType map_type,
boost::optional<boost::filesystem::path> lua_path = boost::none);
};
2 changes: 1 addition & 1 deletion libs/s25main/ingameWindows/iwSave.cpp
Expand Up @@ -199,7 +199,7 @@ void iwLoad::SaveLoad()
if(!table->GetSelection())
return;

if(GAMECLIENT.HostGame(csi, table->GetItemText(*table->GetSelection(), 4), MapType::Savegame))
if(GAMECLIENT.HostGame(csi, {table->GetItemText(*table->GetSelection(), 4), MapType::Savegame}))
{
std::unique_ptr<ILobbyClient> lobbyClient;
if(csi.type == ServerType::Lobby)
Expand Down
4 changes: 3 additions & 1 deletion libs/s25main/network/GameClient.h
Expand Up @@ -13,6 +13,7 @@
#include "factories/GameCommandFactory.h"
#include "gameTypes/AIInfo.h"
#include "gameTypes/ChatDestination.h"
#include "gameTypes/MapDescription.h"
#include "gameTypes/MapInfo.h"
#include "gameTypes/Nation.h"
#include "gameTypes/ServerType.h"
Expand Down Expand Up @@ -79,8 +80,9 @@ class GameClient final :

bool Connect(const std::string& server, const std::string& password, ServerType servertyp, unsigned short port,
bool host, bool use_ipv6);

/// Start the server and connect to it
bool HostGame(const CreateServerInfo& csi, const boost::filesystem::path& map_path, MapType map_type);
bool HostGame(const CreateServerInfo& csi, const MapDescription& map);
void Run();
void Stop();

Expand Down

0 comments on commit 04b1a1b

Please sign in to comment.