mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-27 00:14:40 -07:00
Merge branch 'Cockatrice:master' into toggle-normal-untapping-once
This commit is contained in:
commit
fdd7d4eac0
543 changed files with 82935 additions and 48240 deletions
|
|
@ -48,7 +48,7 @@
|
|||
#include <libcockatrice/protocol/pb/response.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
Server_AbstractParticipant::Server_AbstractParticipant(Server_Game *_game,
|
||||
int _playerId,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@
|
|||
#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/rng/rng_abstract.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/dice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <limits>
|
||||
#include <ranges>
|
||||
|
|
@ -1636,10 +1637,11 @@ void Server_AbstractPlayer::getInfo(ServerInfo_Player *info,
|
|||
bool withUserInfo)
|
||||
{
|
||||
getProperties(*info->mutable_properties(), withUserInfo);
|
||||
if (recipient == this) {
|
||||
if (deck) {
|
||||
info->set_deck_list(deck->writeToString_Native().toStdString());
|
||||
}
|
||||
|
||||
// Deck lists are only shared with other players when the game is in Open Decklists mode,
|
||||
// so a player joining an open lobby can see every deck that was loaded before they joined.
|
||||
if (deck && (recipient == this || game->getShareDecklistsOnLoad())) {
|
||||
info->set_deck_list(deck->writeToString_Native().toStdString());
|
||||
}
|
||||
|
||||
for (Server_Arrow *arrow : arrows) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@
|
|||
#include <libcockatrice/protocol/pb/event_set_card_attr.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_set_card_counter.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/clamped_arithmetic.h>
|
||||
#include <libcockatrice/utility/counter_limits.h>
|
||||
#include <limits>
|
||||
|
||||
Server_Card::Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||
|
|
@ -124,8 +125,8 @@ QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue
|
|||
|
||||
bool Server_Card::setCounter(int _id, int value, Event_SetCardCounter *event)
|
||||
{
|
||||
// Clamp to valid card counter range [0, MAX_COUNTERS_ON_CARD]
|
||||
value = qBound(0, value, MAX_COUNTERS_ON_CARD);
|
||||
// Clamp to valid card counter range [0, MAX_COUNTER_VALUE]
|
||||
value = qBound(0, value, MAX_COUNTER_VALUE);
|
||||
|
||||
const int oldValue = counters.value(_id, 0);
|
||||
if (value == oldValue) {
|
||||
|
|
@ -149,10 +150,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_COUNTERS_ON_CARD] for card counters
|
||||
const int newValue =
|
||||
static_cast<int>(qBound(static_cast<int64_t>(0), result, static_cast<int64_t>(MAX_COUNTERS_ON_CARD)));
|
||||
// Clamp to [0, MAX_COUNTER_VALUE] for card counters
|
||||
const int newValue = addClamped(oldValue, delta, 0, MAX_COUNTER_VALUE);
|
||||
|
||||
if (newValue == oldValue) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public:
|
|||
/**
|
||||
* @brief Sets a card counter to an exact value with clamping.
|
||||
* @param _id The counter ID.
|
||||
* @param value The desired value (clamped to [0, MAX_COUNTERS_ON_CARD]; 0 removes the counter).
|
||||
* @param value The desired value (clamped to [0, MAX_COUNTER_VALUE]; 0 removes the counter).
|
||||
* @param event Optional event to populate with counter state.
|
||||
* @return true if the value changed, false otherwise.
|
||||
*/
|
||||
|
|
@ -173,7 +173,7 @@ public:
|
|||
* @param event Optional event to populate with counter state.
|
||||
* @return true if the value changed, false otherwise.
|
||||
* @note If counter does not exist, starts from 0. Counter is removed if result is 0.
|
||||
* @note Clamps result to [0, MAX_COUNTERS_ON_CARD].
|
||||
* @note Clamps result to [0, MAX_COUNTER_VALUE].
|
||||
*/
|
||||
[[nodiscard]] bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event = nullptr);
|
||||
void setTapped(bool _tapped)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,12 @@
|
|||
#include "server_counter.h"
|
||||
|
||||
#include <libcockatrice/protocol/pb/serverinfo_counter.pb.h>
|
||||
#include <limits>
|
||||
|
||||
Server_Counter::Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count)
|
||||
: id(_id), name(_name), counterColor(_counterColor), radius(_radius), count(_count)
|
||||
{
|
||||
}
|
||||
|
||||
//! \todo Extract overflow-safe arithmetic into shared helper.
|
||||
//! Duplicated in Server_Card::incrementCounter() - keep in sync if modified.
|
||||
bool Server_Counter::incrementCount(int delta)
|
||||
{
|
||||
const int oldCount = count;
|
||||
const auto result = static_cast<int64_t>(count) + static_cast<int64_t>(delta);
|
||||
count = static_cast<int>(qBound(static_cast<int64_t>(std::numeric_limits<int>::min()), result,
|
||||
static_cast<int64_t>(std::numeric_limits<int>::max())));
|
||||
return count != oldCount;
|
||||
}
|
||||
|
||||
void Server_Counter::getInfo(ServerInfo_Counter *info)
|
||||
{
|
||||
info->set_id(id);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include <QString>
|
||||
#include <libcockatrice/protocol/pb/color.pb.h>
|
||||
#include <libcockatrice/utility/clamped_arithmetic.h>
|
||||
#include <limits>
|
||||
|
||||
class ServerInfo_Counter;
|
||||
|
||||
|
|
@ -92,7 +94,12 @@ public:
|
|||
* @return true if the value changed, false otherwise.
|
||||
* @note Clamps result to [INT_MIN, INT_MAX] to prevent overflow.
|
||||
*/
|
||||
[[nodiscard]] bool incrementCount(int delta);
|
||||
[[nodiscard]] bool incrementCount(int delta)
|
||||
{
|
||||
const int oldCount = count;
|
||||
count = addClamped(count, delta, std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
|
||||
return count != oldCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Populates info with this counter's current state for network serialization.
|
||||
|
|
|
|||
|
|
@ -526,10 +526,7 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface,
|
|||
|
||||
if (broadcastUpdate) {
|
||||
ServerInfo_Game gameInfo;
|
||||
gameInfo.set_room_id(room->getId());
|
||||
gameInfo.set_game_id(gameId);
|
||||
gameInfo.set_player_count(getPlayerCount());
|
||||
gameInfo.set_spectators_count(getSpectatorCount());
|
||||
getInfo(gameInfo);
|
||||
emit gameInfoChanged(gameInfo);
|
||||
}
|
||||
|
||||
|
|
@ -588,10 +585,7 @@ void Server_Game::removeParticipant(Server_AbstractParticipant *participant, Eve
|
|||
}
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
gameInfo.set_room_id(room->getId());
|
||||
gameInfo.set_game_id(gameId);
|
||||
gameInfo.set_player_count(getPlayerCount());
|
||||
gameInfo.set_spectators_count(getSpectatorCount());
|
||||
getInfo(gameInfo);
|
||||
emit gameInfoChanged(gameInfo);
|
||||
}
|
||||
|
||||
|
|
@ -847,6 +841,12 @@ void Server_Game::getInfo(ServerInfo_Game &result) const
|
|||
result.set_player_count(getPlayerCount());
|
||||
result.set_started(gameStarted);
|
||||
result.mutable_creator_info()->CopyFrom(*getCreatorInfo());
|
||||
const Server_AbstractParticipant *host = participants.value(hostId, nullptr);
|
||||
if (host != nullptr) {
|
||||
result.mutable_host_info()->CopyFrom(*host->getUserInfo());
|
||||
} else {
|
||||
result.mutable_host_info()->CopyFrom(*getCreatorInfo());
|
||||
}
|
||||
result.set_only_buddies(onlyBuddies);
|
||||
result.set_only_registered(onlyRegistered);
|
||||
result.set_spectators_allowed(getSpectatorsAllowed());
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/rng/rng_abstract.h>
|
||||
#include <libcockatrice/utility/color.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
Server_Player::Server_Player(Server_Game *_game,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue