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

Return-To-The-Roots / s25client / 15702208672

17 Jun 2025 08:30AM UTC coverage: 50.444% (-0.02%) from 50.467%
15702208672

Pull #1534

github

web-flow
Merge 2b146592b into 67a057674
Pull Request #1534: Portrait support

58 of 162 new or added lines in 17 files covered. (35.8%)

23 existing lines in 5 files now uncovered.

22503 of 44610 relevant lines covered (50.44%)

35287.29 hits per line

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

97.37
/libs/s25main/BasePlayerInfo.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 "BasePlayerInfo.h"
6
#include "helpers/serializeEnums.h"
7
#include "gameData/PortraitConsts.h"
8
#include "s25util/colors.h"
9

10
BasePlayerInfo::BasePlayerInfo()
263✔
11
    : ps(PlayerState::Free), portraitIndex(0), nation(Nation::Romans), color(PLAYER_COLORS[0]), team(Team::None)
263✔
12
{}
263✔
13

14
BasePlayerInfo::BasePlayerInfo(Serializer& ser, int serializedVersion, bool lightData)
33✔
15
    : ps(helpers::popEnum<PlayerState>(ser)), aiInfo(!lightData || ps == PlayerState::AI ? ser : AI::Info())
33✔
16
{
17
    if(lightData && !isUsed())
33✔
18
    {
19
        portraitIndex = 0;
6✔
20
        nation = Nation::Romans;
6✔
21
        team = Team::None;
6✔
22
        color = PLAYER_COLORS[0];
6✔
23
    } else
24
    {
25
        name = ser.PopLongString();
27✔
26
        portraitIndex = (serializedVersion >= 1) ? ser.PopUnsignedInt() : 0;
27✔
27
        if(portraitIndex >= Portraits.size())
27✔
28
        {
NEW
29
            portraitIndex = 0;
×
30
        }
31
        nation = helpers::popEnum<Nation>(ser);
27✔
32
        color = ser.PopUnsignedInt();
27✔
33
        team = helpers::popEnum<Team>(ser);
27✔
34
    }
35
}
33✔
36

37
void BasePlayerInfo::Serialize(Serializer& ser, bool lightData) const
29✔
38
{
39
    helpers::pushEnum<uint8_t>(ser, ps);
29✔
40
    if(lightData && !isUsed())
29✔
41
        return;
5✔
42
    if(!lightData || ps == PlayerState::AI)
24✔
43
        aiInfo.serialize(ser);
16✔
44
    ser.PushLongString(name);
24✔
45
    ser.PushUnsignedInt(portraitIndex);
24✔
46
    helpers::pushEnum<uint8_t>(ser, nation);
24✔
47
    ser.PushUnsignedInt(color);
24✔
48
    helpers::pushEnum<uint8_t>(ser, team);
24✔
49
}
50

51
int BasePlayerInfo::GetColorIdx() const
2✔
52
{
53
    return GetColorIdx(color);
2✔
54
}
55

56
int BasePlayerInfo::GetColorIdx(unsigned color) //-V688
2✔
57
{
58
    for(int i = 0; i < static_cast<int>(PLAYER_COLORS.size()); ++i)
18✔
59
    {
60
        if(PLAYER_COLORS[i] == color)
17✔
61
            return i;
1✔
62
    }
63
    return -1;
1✔
64
}
65

66
int BasePlayerInfo::getCurrentVersion()
6✔
67
{
68
    // 0: Initial
69
    // 1: Added portraitIndex
70
    return 1;
6✔
71
}
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