mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 20:43:54 -07:00
Refine command zone counters and unify counter clamp arithmetic
- Route value updates through the virtual setValue() so
CommanderTaxCounter's tooltip tracks the live value instead of
freezing at its initial value
- Reject deletion of reserved tax counters in cmdDelCounter; they are
server-managed and must persist for the game
- Register aMoveToCommandZone and aViewCommandZone as bindable
shortcuts, matching their sibling move/view zone actions
- Extract overflow-safe clamped addition into addClamped(), shared by
Server_Card and Server_Counter instead of duplicated
- Update stale comments: the clip-container note (now used by
CommandZone) and CommandZone's layout docs (defer to
SelectZone::layoutCardsVertically)
This commit is contained in:
parent
754b31cc29
commit
240ca7029f
8 changed files with 37 additions and 22 deletions
|
|
@ -139,10 +139,8 @@ bool Server_Card::setCounter(int _id, int value, Event_SetCardCounter *event)
|
|||
bool Server_Card::incrementCounter(int counterId, int delta, Event_SetCardCounter *event)
|
||||
{
|
||||
const int oldValue = counters.value(counterId, 0);
|
||||
const auto result = static_cast<int64_t>(oldValue) + static_cast<int64_t>(delta);
|
||||
// Clamp to [0, MAX_COUNTER_VALUE] for card counters
|
||||
const int newValue =
|
||||
static_cast<int>(qBound(static_cast<int64_t>(0), result, static_cast<int64_t>(MAX_COUNTER_VALUE)));
|
||||
const int newValue = addClamped(oldValue, delta, 0, MAX_COUNTER_VALUE);
|
||||
|
||||
if (newValue == oldValue) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QString>
|
||||
#include <libcockatrice/protocol/pb/color.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <limits>
|
||||
|
||||
class ServerInfo_Counter;
|
||||
|
|
@ -128,11 +129,8 @@ public:
|
|||
*/
|
||||
[[nodiscard]] bool incrementCount(int delta)
|
||||
{
|
||||
const auto result = static_cast<int64_t>(count) + static_cast<int64_t>(delta);
|
||||
const int clamped =
|
||||
static_cast<int>(qBound(static_cast<int64_t>(minValue), result, static_cast<int64_t>(maxValue)));
|
||||
int oldCount = count;
|
||||
count = clamped;
|
||||
const int oldCount = count;
|
||||
count = addClamped(count, delta, minValue, maxValue);
|
||||
return count != oldCount;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -549,8 +549,11 @@ Server_Player::cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &
|
|||
|
||||
const int counterId = cmd.counter_id();
|
||||
|
||||
if (isCommandZoneCounterBlocked(counterId)) {
|
||||
return Response::RespContextError;
|
||||
// Reserved tax counters are server-managed system counters and must never be
|
||||
// deleted by a client. When the command zone is disabled they don't exist, so
|
||||
// a lookup would fail anyway; when it's enabled they must persist for the game.
|
||||
if (CounterIds::isTaxCounter(counterId)) {
|
||||
return Response::RespFunctionNotAllowed;
|
||||
}
|
||||
|
||||
Server_Counter *counter = counters.value(counterId, nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue