Cockatrice 2026-06-01-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
Server_Counter Class Reference

Represents a player counter with overflow-safe increment arithmetic. More...

#include <server_counter.h>

Public Member Functions

 Server_Counter (int _id, const QString &_name, const color &_counterColor, int _radius, int _count=0)
 ~Server_Counter ()
int getId () const
QString getName () const
const color & getColor () const
int getRadius () const
int getCount () const
bool setCount (int _count)
 Sets the counter to an exact value.
bool incrementCount (int delta)
 Increments the counter by delta with overflow-safe arithmetic.
void getInfo (ServerInfo_Counter *info)
 Populates info with this counter's current state for network serialization.

Protected Attributes

int id
QString name
color counterColor
int radius
int count

Detailed Description

Represents a player counter with overflow-safe increment arithmetic.

All value modifications return whether the value actually changed, enabling callers to skip unnecessary network events.

Note
Direct assignment via setCount() does not clamp; only incrementCount() enforces int boundary saturation.
Unlike card counters, player counters are never auto-removed when they reach zero - they persist with value 0.

Constructor & Destructor Documentation

◆ Server_Counter()

Server_Counter::Server_Counter ( int _id,
const QString & _name,
const color & _counterColor,
int _radius,
int _count = 0 )

◆ ~Server_Counter()

Server_Counter::~Server_Counter ( )
inline

Member Function Documentation

◆ getColor()

const color & Server_Counter::getColor ( ) const
inline

◆ getCount()

int Server_Counter::getCount ( ) const
inline
Here is the caller graph for this function:

◆ getId()

int Server_Counter::getId ( ) const
inline
Here is the caller graph for this function:

◆ getInfo()

void Server_Counter::getInfo ( ServerInfo_Counter * info)

Populates info with this counter's current state for network serialization.

Parameters
infoThe protobuf message to populate.

◆ getName()

QString Server_Counter::getName ( ) const
inline

◆ getRadius()

int Server_Counter::getRadius ( ) const
inline

◆ incrementCount()

bool Server_Counter::incrementCount ( int delta)
nodiscard

Increments the counter by delta with overflow-safe arithmetic.

Parameters
deltaThe amount to add (may be negative for decrement).
Returns
true if the value changed, false otherwise.
Note
Clamps result to [INT_MIN, INT_MAX] to prevent overflow.
Todo
Extract overflow-safe arithmetic into shared helper. Duplicated in Server_Card::incrementCounter() - keep in sync if modified.
Here is the caller graph for this function:

◆ setCount()

bool Server_Counter::setCount ( int _count)
inlinenodiscard

Sets the counter to an exact value.

Parameters
_countThe new value (assigned directly without clamping).
Returns
true if the value changed, false otherwise.
Warning
This performs raw assignment. For overflow-safe incrementing, use incrementCount().
Here is the caller graph for this function:

Member Data Documentation

◆ count

int Server_Counter::count
protected

◆ counterColor

color Server_Counter::counterColor
protected

◆ id

int Server_Counter::id
protected

◆ name

QString Server_Counter::name
protected

◆ radius

int Server_Counter::radius
protected

The documentation for this class was generated from the following files: