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

Return-To-The-Roots / s25client / 21780228483

07 Feb 2026 12:38PM UTC coverage: 50.817% (+0.06%) from 50.754%
21780228483

push

github

Flow86
Also use references for non-NULL arguments in `GamePlayer`

44 of 59 new or added lines in 11 files covered. (74.58%)

520 existing lines in 14 files now uncovered.

22787 of 44841 relevant lines covered (50.82%)

42084.45 hits per line

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

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

5
#include "nofWorkman.h"
6
#include "EventManager.h"
7
#include "SoundManager.h"
8
#include "buildings/nobUsual.h"
9
#include "world/GameWorld.h"
10
#include "gameData/GameConsts.h"
11
#include "gameData/JobConsts.h"
12

13
nofWorkman::nofWorkman(const Job job, const MapPoint pos, const unsigned char player, nobUsual* workplace)
5✔
14
    : nofBuildingWorker(job, pos, player, workplace)
5✔
15
{}
5✔
16

17
nofWorkman::nofWorkman(SerializedGameData& sgd, const unsigned obj_id) : nofBuildingWorker(sgd, obj_id) {}
1✔
18

19
void nofWorkman::HandleDerivedEvent(const unsigned /*id*/)
11✔
20
{
21
    switch(state)
11✔
22
    {
23
        case State::Waiting1: HandleStateWaiting1(); break;
5✔
24
        case State::Work: HandleStateWork(); break;
3✔
25
        case State::Waiting2: HandleStateWaiting2(); break;
3✔
UNCOV
26
        default: break;
×
27
    }
28
}
11✔
29

30
bool nofWorkman::StartWorking()
4✔
31
{
32
    current_ev = GetEvMgr().AddEvent(this, JOB_CONSTS[job_].work_length, 1);
4✔
33
    state = State::Work;
4✔
34
    workplace->is_working = true;
4✔
35
    // Waren verbrauchen
36
    workplace->ConsumeWares();
4✔
37
    return true;
4✔
38
}
39

40
void nofWorkman::HandleStateWaiting1()
5✔
41
{
42
    current_ev = nullptr;
5✔
43
    if(!StartWorking())
5✔
44
    {
45
        state = State::WaitingForWaresOrProductionStopped;
1✔
46
        workplace->StartNotWorking();
1✔
47
    }
48
}
5✔
49

50
void nofWorkman::HandleStateWaiting2()
3✔
51
{
52
    current_ev = nullptr;
3✔
53
    // Ware erzeugen... (noch nicht "richtig"!, sondern nur viruell erstmal)
54
    if(!(ware = ProduceWare()).has_value())
3✔
55
    {
56
        // Soll keine erzeugt werden --> wieder anfangen zu arbeiten
UNCOV
57
        TryToWork();
×
58
    } else
59
    {
60
        // und diese raustragen
61
        StartWalking(Direction::SouthEast);
3✔
62
        state = State::CarryoutWare;
3✔
63
    }
64

65
    // abgeleiteten Klassen Bescheid sagen
66
    WorkFinished();
3✔
67
}
3✔
68

69
void nofWorkman::HandleStateWork()
3✔
70
{
71
    // Nach Arbeiten wird noch ein bisschen gewartet, bevor das Produkt herausgetragen wird
72
    // Bei 0 mind. 1 GF
73
    current_ev = GetEvMgr().AddEvent(this, JOB_CONSTS[job_].wait2_length ? JOB_CONSTS[job_].wait2_length : 1, 1);
3✔
74
    state = State::Waiting2;
3✔
75
    // wir arbeiten nicht mehr
76
    workplace->is_working = false;
3✔
77

78
    // Evtl. Sounds löschen
79
    if(was_sounding)
3✔
80
    {
UNCOV
81
        world->GetSoundMgr().stopSounds(*this);
×
UNCOV
82
        was_sounding = false;
×
83
    }
84
}
3✔
85

86
namespace {
87
struct NodeHasResource
88
{
89
    const GameWorld& world;
90
    const ResourceType res;
UNCOV
91
    NodeHasResource(const GameWorld& world, const ResourceType res) : world(world), res(res) {}
×
92

UNCOV
93
    bool operator()(const MapPoint pt) { return world.GetNode(pt).resources.has(res); }
×
94
};
95
} // namespace
96

97
MapPoint nofWorkman::FindPointWithResource(ResourceType type) const
×
98
{
99
    // Alle Punkte durchgehen, bis man einen findet, wo man graben kann
100
    const std::vector<MapPoint> pts =
101
      world->GetMatchingPointsInRadius<1>(pos, MINER_RADIUS, NodeHasResource(*world, type), true);
×
UNCOV
102
    if(!pts.empty())
×
UNCOV
103
        return pts.front();
×
104

105
    workplace->OnOutOfResources();
×
106

107
    return MapPoint::Invalid();
×
108
}
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