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

Return-To-The-Roots / s25client / 15192227550

22 May 2025 04:45PM UTC coverage: 50.301% (+0.02%) from 50.286%
15192227550

Pull #1772

github

web-flow
Merge 124de9c89 into 0d2a837ba
Pull Request #1772: Use C++17 variable templates for traits

12 of 13 new or added lines in 6 files covered. (92.31%)

3 existing lines in 2 files now uncovered.

22365 of 44462 relevant lines covered (50.3%)

35013.35 hits per line

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

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

5
#include "GameCommands.h"
6
#include "GamePlayer.h"
7
#include "WineLoader.h"
8
#include "buildings/nobBaseWarehouse.h"
9
#include "buildings/nobHarborBuilding.h"
10
#include "buildings/nobMilitary.h"
11
#include "buildings/nobShipYard.h"
12
#include "buildings/nobTemple.h"
13
#include "enum_cast.hpp"
14
#include "helpers/MaxEnumValue.h"
15
#include "helpers/format.hpp"
16
#include "world/GameWorld.h"
17
#include "nodeObjs/noFlag.h"
18
#include "nodeObjs/noShip.h"
19
#include <algorithm>
20
#include <stdexcept>
21

22
namespace gc {
23

24
void SetFlag::Execute(GameWorld& world, uint8_t playerId)
256✔
25
{
26
    world.SetFlag(pt_, playerId);
256✔
27
}
256✔
28

29
void DestroyFlag::Execute(GameWorld& world, uint8_t playerId)
209✔
30
{
31
    world.DestroyFlag(pt_, playerId);
209✔
32
}
209✔
33

34
BuildRoad::BuildRoad(Serializer& ser)
59✔
35
    : Coords(GCType::BuildRoad, ser), boat_road(ser.PopBool()), route(ser.PopUnsignedInt())
59✔
36
{
37
    for(Direction& i : route)
333✔
38
        i = helpers::popEnum<Direction>(ser);
274✔
39
}
59✔
40

41
void BuildRoad::Serialize(Serializer& ser) const
118✔
42
{
43
    Coords::Serialize(ser);
118✔
44

45
    ser.PushBool(boat_road);
118✔
46
    ser.PushUnsignedInt(route.size());
118✔
47
    for(auto i : route)
666✔
48
        helpers::pushEnum<uint8_t>(ser, i);
548✔
49
}
118✔
50

51
void BuildRoad::Execute(GameWorld& world, uint8_t playerId)
70✔
52
{
53
    world.BuildRoad(playerId, boat_road, pt_, route);
70✔
54
}
70✔
55

56
DestroyRoad::DestroyRoad(Serializer& ser)
6✔
57
    : Coords(GCType::DestroyRoad, ser), start_dir(helpers::popEnum<Direction>(ser))
6✔
58
{}
6✔
59

60
void DestroyRoad::Serialize(Serializer& ser) const
12✔
61
{
62
    Coords::Serialize(ser);
12✔
63

64
    helpers::pushEnum<uint8_t>(ser, start_dir);
12✔
65
}
12✔
66

67
void DestroyRoad::Execute(GameWorld& world, uint8_t playerId)
6✔
68
{
69
    auto* flag = world.GetSpecObj<noFlag>(pt_);
6✔
70
    if(flag && flag->GetPlayer() == playerId)
6✔
71
        flag->DestroyRoad(start_dir);
4✔
72
}
6✔
73

74
UpgradeRoad::UpgradeRoad(Serializer& ser)
5✔
75
    : Coords(GCType::UpgradeRoad, ser), start_dir(helpers::popEnum<Direction>(ser))
5✔
76
{}
5✔
77

78
void UpgradeRoad::Serialize(Serializer& ser) const
10✔
79
{
80
    Coords::Serialize(ser);
10✔
81
    helpers::pushEnum<uint8_t>(ser, start_dir);
10✔
82
}
10✔
83

84
void UpgradeRoad::Execute(GameWorld& world, uint8_t playerId)
5✔
85
{
86
    auto* flag = world.GetSpecObj<noFlag>(pt_);
5✔
87
    if(flag && flag->GetPlayer() == playerId)
5✔
88
        flag->UpgradeRoad(start_dir);
4✔
89
}
5✔
90

91
ChangeDistribution::ChangeDistribution(Deserializer& ser) : GameCommand(GCType::ChangeDistribution)
2✔
92
{
93
    if(ser.getDataVersion() >= 1)
2✔
94
        helpers::popContainer(ser, data);
2✔
95
    else
96
    {
97
        std::array<Distributions::value_type,
98
                   std::tuple_size_v<Distributions> - 3> tmpData; // 3 entries for wine addon
UNCOV
99
        helpers::popContainer(ser, tmpData);
×
100
        size_t srcIdx = 0, tgtIdx = 0;
×
101
        for(const auto& mapping : distributionMap)
×
102
        {
103
            // skip over wine buildings in tmpData
104
            const auto setting =
105
              wineaddon::isWineAddonBuildingType(std::get<BuildingType>(mapping)) ? 0 : tmpData[srcIdx++];
×
106
            data[tgtIdx++] = setting;
×
107
        }
108
    }
109
}
2✔
110

111
void ChangeDistribution::Execute(GameWorld& world, uint8_t playerId)
6✔
112
{
113
    world.GetPlayer(playerId).ChangeDistribution(data);
6✔
114
}
6✔
115

116
void ChangeBuildOrder::Execute(GameWorld& world, uint8_t playerId)
2✔
117
{
118
    world.GetPlayer(playerId).ChangeBuildOrder(useCustomBuildOrder, data);
2✔
119
}
2✔
120

121
void SetBuildingSite::Execute(GameWorld& world, uint8_t playerId)
24✔
122
{
123
    world.SetBuildingSite(bt, pt_, playerId);
24✔
124
}
24✔
125

126
void DestroyBuilding::Execute(GameWorld& world, uint8_t playerId)
3✔
127
{
128
    world.DestroyBuilding(pt_, playerId);
3✔
129
}
3✔
130

131
void ChangeTransport::Execute(GameWorld& world, uint8_t playerId)
2✔
132
{
133
    world.GetPlayer(playerId).ConvertTransportData(data);
2✔
134
}
2✔
135

136
void ChangeMilitary::Execute(GameWorld& world, uint8_t playerId)
52✔
137
{
138
    world.GetPlayer(playerId).ChangeMilitarySettings(data);
52✔
139
}
52✔
140

141
ChangeTools::ChangeTools(const ToolSettings& data, const int8_t* order_delta)
6✔
142
    : GameCommand(GCType::ChangeTools), data(data), orders()
6✔
143
{
144
    if(order_delta != nullptr)
6✔
145
        std::copy_n(order_delta, orders.size(), orders.begin());
3✔
146
}
6✔
147

148
void ChangeTools::Execute(GameWorld& world, uint8_t playerId)
6✔
149
{
150
    world.GetPlayer(playerId).ChangeToolsSettings(data, orders);
6✔
151
}
6✔
152

153
void CallSpecialist::Execute(GameWorld& world, uint8_t playerId)
32✔
154
{
155
    world.GetPlayer(playerId).CallFlagWorker(pt_, job);
32✔
156
}
32✔
157

158
void Attack::Execute(GameWorld& world, uint8_t playerId)
22✔
159
{
160
    world.Attack(playerId, pt_, soldiers_count, strong_soldiers);
22✔
161
}
22✔
162

163
void SeaAttack::Execute(GameWorld& world, uint8_t playerId)
35✔
164
{
165
    world.AttackViaSea(playerId, pt_, soldiers_count, strong_soldiers);
35✔
166
}
35✔
167

168
void SetCoinsAllowed::Execute(GameWorld& world, uint8_t playerId)
5✔
169
{
170
    auto* const bld = world.GetSpecObj<nobMilitary>(pt_);
5✔
171
    if(bld && bld->GetPlayer() == playerId)
5✔
172
        bld->SetCoinsAllowed(enabled);
3✔
173
}
5✔
174

175
void SetTroopLimit::Execute(GameWorld& world, uint8_t playerId)
13✔
176
{
177
    auto* const bld = world.GetSpecObj<nobMilitary>(pt_);
13✔
178
    if(bld && bld->GetPlayer() == playerId)
13✔
179
        bld->SetTroopLimit(rank, count);
13✔
180
}
13✔
181

182
void SetProductionEnabled::Execute(GameWorld& world, uint8_t playerId)
8✔
183
{
184
    auto* const bld = world.GetSpecObj<nobUsual>(pt_);
8✔
185
    if(bld && bld->GetPlayer() == playerId)
8✔
186
        bld->SetProductionEnabled(enabled);
6✔
187
}
8✔
188

189
void SetInventorySetting::Execute(GameWorld& world, uint8_t playerId)
45✔
190
{
191
    auto* const bld = world.GetSpecObj<nobBaseWarehouse>(pt_);
45✔
192
    if(bld && bld->GetPlayer() == playerId)
45✔
193
        bld->SetInventorySetting(what, state);
45✔
194
}
45✔
195

196
void SetAllInventorySettings::Execute(GameWorld& world, uint8_t playerId)
4✔
197
{
198
    auto* const bld = world.GetSpecObj<nobBaseWarehouse>(pt_);
4✔
199
    if(bld && bld->GetPlayer() == playerId)
4✔
200
        bld->SetAllInventorySettings(isJob, states);
4✔
201
}
4✔
202

203
void ChangeReserve::Execute(GameWorld& world, uint8_t playerId)
15✔
204
{
205
    auto* const bld = world.GetSpecObj<nobBaseWarehouse>(pt_);
15✔
206
    if(bld && bld->GetPlayer() == playerId)
15✔
207
        bld->SetRealReserve(rank, count);
15✔
208
}
15✔
209

210
void Surrender::Execute(GameWorld& world, uint8_t playerId)
1✔
211
{
212
    world.GetPlayer(playerId).Surrender();
1✔
213
}
1✔
214

215
void CheatArmageddon::Execute(GameWorld& world, unsigned char /*playerId*/)
1✔
216
{
217
    world.Armageddon();
1✔
218
}
1✔
219

220
void DestroyAll::Execute(GameWorld& world, uint8_t playerId)
1✔
221
{
222
    world.Armageddon(playerId);
1✔
223
}
1✔
224

225
void SuggestPact::Execute(GameWorld& world, uint8_t playerId)
8✔
226
{
227
    world.GetPlayer(playerId).SuggestPact(targetPlayer, pt, duration);
8✔
228
}
8✔
229

230
void AcceptPact::Execute(GameWorld& world, uint8_t playerId)
21✔
231
{
232
    world.GetPlayer(fromPlayer).AcceptPact(id, pt, playerId);
21✔
233
}
21✔
234

235
void CancelPact::Execute(GameWorld& world, uint8_t playerId)
6✔
236
{
237
    world.GetPlayer(playerId).CancelPact(pt, otherPlayer);
6✔
238
}
6✔
239

240
void NotifyAlliesOfLocation::Execute(GameWorld& world, uint8_t playerId)
6✔
241
{
242
    world.GetPlayer(playerId).NotifyAlliesOfLocation(pt_);
6✔
243
}
6✔
244

245
void SetShipYardMode::Execute(GameWorld& world, uint8_t playerId)
5✔
246
{
247
    auto* const bld = world.GetSpecObj<nobShipYard>(pt_);
5✔
248
    if(bld && bld->GetPlayer() == playerId)
5✔
249
        bld->SetMode(buildShips ? nobShipYard::Mode::Ships : nobShipYard::Mode::Boats);
5✔
250
}
5✔
251

252
void SetTempleProductionMode::Execute(GameWorld& world, uint8_t playerId)
×
253
{
254
    auto* const bld = world.GetSpecObj<nobTemple>(pt_);
×
255
    if(bld && bld->GetPlayer() == playerId)
×
256
        bld->SetProductionMode(productionMode);
×
257
}
×
258

259
void StartStopExpedition::Execute(GameWorld& world, uint8_t playerId)
6✔
260
{
261
    auto* const bld = world.GetSpecObj<nobHarborBuilding>(pt_);
6✔
262
    if(bld && bld->GetPlayer() == playerId)
6✔
263
    {
264
        if(start)
6✔
265
            bld->StartExpedition();
4✔
266
        else
267
            bld->StopExpedition();
2✔
268
    }
269
}
6✔
270

271
void StartStopExplorationExpedition::Execute(GameWorld& world, uint8_t playerId)
8✔
272
{
273
    auto* const bld = world.GetSpecObj<nobHarborBuilding>(pt_);
8✔
274
    if(bld && bld->GetPlayer() == playerId)
8✔
275
    {
276
        if(start)
8✔
277
            bld->StartExplorationExpedition();
6✔
278
        else
279
            bld->StopExplorationExpedition();
2✔
280
    }
281
}
8✔
282

283
void ExpeditionCommand::Execute(GameWorld& world, uint8_t playerId)
12✔
284
{
285
    noShip* ship = world.GetPlayer(playerId).GetShipByID(this->ship_id);
12✔
286
    if(!ship)
12✔
287
        return;
×
288

289
    switch(action)
12✔
290
    {
291
        case Action::FoundColony: ship->FoundColony(); break;
4✔
292
        case Action::CancelExpedition: ship->CancelExpedition(); break;
3✔
293
        case Action::North: ship->ContinueExpedition(ShipDirection::North); break;
2✔
294
        case Action::NorthEast: ship->ContinueExpedition(ShipDirection::NorthEast); break;
×
295
        case Action::SouthEast: ship->ContinueExpedition(ShipDirection::SouthEast); break;
1✔
296
        case Action::South: ship->ContinueExpedition(ShipDirection::South); break;
2✔
297
        case Action::SouthWest: ship->ContinueExpedition(ShipDirection::SouthWest); break;
×
298
        case Action::NorthWest: ship->ContinueExpedition(ShipDirection::NorthWest); break;
×
299
    }
300
}
301

302
/// Fuehrt das GameCommand aus
303
void TradeOverLand::Execute(GameWorld& world, uint8_t playerId)
18✔
304
{
305
    auto* const bld = world.GetSpecObj<nobBaseWarehouse>(pt_);
18✔
306
    if(bld)
18✔
307
        world.GetPlayer(playerId).Trade(bld, what, count);
18✔
308
}
18✔
309

310
} // namespace gc
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