• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 4621997437

pending completion
4621997437

push

github

Flow86
fix path

21886 of 43348 relevant lines covered (50.49%)

31880.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.0
/libs/s25main/QuickStartGame.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "QuickStartGame.h"
6
#include "Loader.h"
7
#include "MusicPlayer.h"
8
#include "RttrConfig.h"
9
#include "Settings.h"
10
#include "WindowManager.h"
11
#include "desktops/dskGameLoader.h"
12
#include "desktops/dskSelectMap.h"
13
#include "ingameWindows/iwConnecting.h"
14
#include "ingameWindows/iwMusicPlayer.h"
15
#include "network/ClientInterface.h"
16
#include "network/CreateServerInfo.h"
17
#include "network/GameClient.h"
18
#include "gameData/ApplicationLoader.h"
19
#include "s25util/Log.h"
20
#include "s25util/strAlgos.h"
21
#include <boost/filesystem.hpp>
22

23
class SwitchOnStart : public ClientInterface
24
{
25
public:
26
    SwitchOnStart() { GAMECLIENT.SetInterface(this); }
×
27
    ~SwitchOnStart() override { GAMECLIENT.RemoveInterface(this); }
×
28

29
    void CI_GameLoading(std::shared_ptr<Game> game) override
×
30
    {
31
        WINDOWMANAGER.Switch(std::make_unique<dskGameLoader>(std::move(game)));
×
32
    }
×
33
};
34

35
std::vector<AI::Info> ParseAIOptions(const std::vector<std::string>& aiOptions)
5✔
36
{
37
    std::vector<AI::Info> aiInfos;
5✔
38

39
    for(const std::string& aiOption : aiOptions)
15✔
40
    {
41
        const auto aiOption_lower = s25util::toLower(aiOption);
11✔
42
        AI::Type type = AI::Type::Dummy;
11✔
43
        if(aiOption_lower == "aijh")
11✔
44
            type = AI::Type::Default;
5✔
45
        else if(aiOption_lower != "dummy")
6✔
46
            throw std::invalid_argument("Invalid AI player name: " + aiOption_lower);
1✔
47

48
        aiInfos.push_back({type, AI::Level::Hard});
10✔
49
    }
11✔
50

51
    return aiInfos;
4✔
52
}
1✔
53

54
bool QuickStartGame(const boost::filesystem::path& mapOrReplayPath, const std::vector<std::string>& ais)
×
55
{
56
    if(!exists(mapOrReplayPath))
×
57
    {
58
        LOG.write(_("Given map or replay (%1%) does not exist!")) % mapOrReplayPath;
×
59
        return false;
×
60
    }
61

62
    ApplicationLoader loader(RTTRCONFIG, LOADER, LOG, SETTINGS.sound.playlist);
×
63
    if(!loader.load())
×
64
        return false;
×
65
    if(loader.getPlaylist())
×
66
        MUSICPLAYER.SetPlaylist(std::move(*loader.getPlaylist()));
×
67
    if(SETTINGS.sound.musicEnabled)
×
68
        MUSICPLAYER.Play();
×
69

70
    // An AI-battle is a single-player game.
71
    const bool isSinglePlayer = !ais.empty();
×
72
    std::vector<AI::Info> aiInfos;
×
73
    try
74
    {
75
        aiInfos = ParseAIOptions(ais);
×
76
    } catch(const std::invalid_argument& e)
×
77
    {
78
        LOG.write(e.what());
×
79
        return false;
×
80
    }
×
81

82
    const CreateServerInfo csi(isSinglePlayer ? ServerType::Local : ServerType::Direct, SETTINGS.server.localPort,
×
83
                               _("Unlimited Play"));
×
84

85
    LOG.write(_("Loading game...\n"));
×
86
    const std::string extension = s25util::toLower(mapOrReplayPath.extension().string());
×
87

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

90
    if((extension == ".sav" && GAMECLIENT.HostGame(csi, mapOrReplayPath, MapType::Savegame))
×
91
       || ((extension == ".swd" || extension == ".wld") && GAMECLIENT.HostGame(csi, mapOrReplayPath, MapType::OldMap)))
×
92
    {
93
        GAMECLIENT.SetAIBattlePlayers(std::move(aiInfos));
×
94
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwConnecting>(csi.type, nullptr));
×
95
        return true;
×
96
    } else
97
    {
98
        SwitchOnStart switchOnStart;
×
99
        return GAMECLIENT.StartReplay(mapOrReplayPath);
×
100
    }
×
101
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc