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

Return-To-The-Roots / s25client / 15703316495

17 Jun 2025 09:20AM UTC coverage: 50.448% (-0.02%) from 50.467%
15703316495

push

github

web-flow
Merge pull request #1534 from tehKaiN/portrait-support

Add support for player/nation portraits

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

23 existing lines in 5 files now uncovered.

22505 of 44610 relevant lines covered (50.45%)

35490.83 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()
259✔
11
    : ps(PlayerState::Free), portraitIndex(0), nation(Nation::Romans), color(PLAYER_COLORS[0]), team(Team::None)
259✔
12
{}
259✔
13

14
BasePlayerInfo::BasePlayerInfo(Serializer& ser, int serializedVersion, bool lightData)
29✔
15
    : ps(helpers::popEnum<PlayerState>(ser)), aiInfo(!lightData || ps == PlayerState::AI ? ser : AI::Info())
29✔
16
{
17
    if(lightData && !isUsed())
29✔
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();
23✔
26
        portraitIndex = (serializedVersion >= 1) ? ser.PopUnsignedInt() : 0;
23✔
27
        if(portraitIndex >= Portraits.size())
23✔
28
        {
NEW
29
            portraitIndex = 0;
×
30
        }
31
        nation = helpers::popEnum<Nation>(ser);
23✔
32
        color = ser.PopUnsignedInt();
23✔
33
        team = helpers::popEnum<Team>(ser);
23✔
34
    }
35
}
29✔
36

37
void BasePlayerInfo::Serialize(Serializer& ser, bool lightData) const
25✔
38
{
39
    helpers::pushEnum<uint8_t>(ser, ps);
25✔
40
    if(lightData && !isUsed())
25✔
41
        return;
5✔
42
    if(!lightData || ps == PlayerState::AI)
20✔
43
        aiInfo.serialize(ser);
12✔
44
    ser.PushLongString(name);
20✔
45
    ser.PushUnsignedInt(portraitIndex);
20✔
46
    helpers::pushEnum<uint8_t>(ser, nation);
20✔
47
    ser.PushUnsignedInt(color);
20✔
48
    helpers::pushEnum<uint8_t>(ser, team);
20✔
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()
2✔
67
{
68
    // 0: Initial
69
    // 1: Added portraitIndex
70
    return 1;
2✔
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