Cockatrice
2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Toggle main menu visibility
Loading...
Searching...
No Matches
server_counter.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (C) 2008 by Max-Wilhelm Bruker *
3
* brukie@laptop *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#ifndef SERVER_COUNTER_H
21
#define SERVER_COUNTER_H
22
23
#include <QString>
24
#include <libcockatrice/protocol/pb/color.pb.h>
25
#include <
libcockatrice/utility/clamped_arithmetic.h
>
26
#include <limits>
27
28
class
ServerInfo_Counter
;
29
42
class
Server_Counter
43
{
44
protected
:
45
int
id
;
46
QString
name
;
47
color
counterColor
;
48
int
radius
;
49
int
count
;
50
51
public
:
52
Server_Counter
(
int
_id,
const
QString &_name,
const
color
&_counterColor,
int
_radius,
int
_count = 0);
53
~Server_Counter
()
54
{
55
}
56
int
getId
()
const
57
{
58
return
id
;
59
}
60
QString
getName
()
const
61
{
62
return
name
;
63
}
64
const
color
&
getColor
()
const
65
{
66
return
counterColor
;
67
}
68
int
getRadius
()
const
69
{
70
return
radius
;
71
}
72
int
getCount
()
const
73
{
74
return
count
;
75
}
76
84
[[nodiscard]]
bool
setCount
(
int
_count)
85
{
86
const
int
oldCount =
count
;
87
count
= _count;
88
return
count
!= oldCount;
89
}
90
97
[[nodiscard]]
bool
incrementCount
(
int
delta)
98
{
99
const
int
oldCount =
count
;
100
count
=
addClamped
(
count
, delta, std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
101
return
count
!= oldCount;
102
}
103
108
void
getInfo
(
ServerInfo_Counter
*info);
109
};
110
111
#endif
clamped_arithmetic.h
addClamped
int addClamped(int value, int delta, int minValue, int maxValue)
Overflow-safe clamped addition: returns value + delta bounded to [minValue, maxValue].
Definition
clamped_arithmetic.h:16
Server_Counter::~Server_Counter
~Server_Counter()
Definition
server_counter.h:53
Server_Counter::id
int id
Definition
server_counter.h:45
Server_Counter::incrementCount
bool incrementCount(int delta)
Increments the counter by delta with overflow-safe arithmetic.
Definition
server_counter.h:97
Server_Counter::radius
int radius
Definition
server_counter.h:48
Server_Counter::getRadius
int getRadius() const
Definition
server_counter.h:68
Server_Counter::counterColor
color counterColor
Definition
server_counter.h:47
Server_Counter::getName
QString getName() const
Definition
server_counter.h:60
Server_Counter::Server_Counter
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count=0)
Definition
server_counter.cpp:8
Server_Counter::getInfo
void getInfo(ServerInfo_Counter *info)
Populates info with this counter's current state for network serialization.
Definition
server_counter.cpp:13
Server_Counter::setCount
bool setCount(int _count)
Sets the counter to an exact value.
Definition
server_counter.h:84
Server_Counter::getCount
int getCount() const
Definition
server_counter.h:72
Server_Counter::getColor
const color & getColor() const
Definition
server_counter.h:64
Server_Counter::count
int count
Definition
server_counter.h:49
Server_Counter::getId
int getId() const
Definition
server_counter.h:56
Server_Counter::name
QString name
Definition
server_counter.h:46
ServerInfo_Counter
Definition
serverinfo_counter.proto:3
color
Definition
color.proto:4
libcockatrice_network
libcockatrice
network
server
remote
game
server_counter.h
Generated by
1.18.0