Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
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>
26#include <limits>
27
29
43{
44protected:
45 int id;
46 QString name;
48 int radius;
49 int count;
50
51public:
52 Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
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
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()
Definition server_counter.h:53
int id
Definition server_counter.h:45
bool incrementCount(int delta)
Increments the counter by delta with overflow-safe arithmetic.
Definition server_counter.h:97
int radius
Definition server_counter.h:48
int getRadius() const
Definition server_counter.h:68
color counterColor
Definition server_counter.h:47
QString getName() const
Definition server_counter.h:60
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count=0)
Definition server_counter.cpp:5
void getInfo(ServerInfo_Counter *info)
Populates info with this counter's current state for network serialization.
Definition server_counter.cpp:10
bool setCount(int _count)
Sets the counter to an exact value.
Definition server_counter.h:84
int getCount() const
Definition server_counter.h:72
const color & getColor() const
Definition server_counter.h:64
int count
Definition server_counter.h:49
int getId() const
Definition server_counter.h:56
QString name
Definition server_counter.h:46
Definition serverinfo_counter.proto:3
Definition color.proto:4