Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
server_cardzone.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_CARDZONE_H
21#define SERVER_CARDZONE_H
22
23#include <QMap>
24#include <QSet>
25#include <QString>
26#include <libcockatrice/protocol/pb/serverinfo_zone.pb.h>
27
28class Server_Card;
31class Server_Game;
33
35{
36private:
38 QString name;
39 bool has_coords; // having coords means this zone has x and y coordinates
40 ServerInfo_Zone::ZoneType type;
45 QList<Server_Card *> cards;
46 QMap<int, QMap<int, Server_Card *>> coordinateMap; // y -> (x -> card)
47 QMap<int, QMultiMap<QString, int>> freePilesMap; // y -> (cardName -> x)
48 QMap<int, int> freeSpaceMap; // y -> x
49 void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
50 void insertCardIntoCoordMap(Server_Card *card, int x, int y);
51
52public:
54 const QString &_name,
55 bool _has_coords,
56 ServerInfo_Zone::ZoneType _type);
58
59 [[nodiscard]] const QList<Server_Card *> &getCards() const
60 {
61 return cards;
62 }
63 int removeCard(Server_Card *card);
64 int removeCard(Server_Card *card, bool &wasLookedAt);
65 Server_Card *getCard(int id, int *position = nullptr, bool remove = false);
66
67 [[nodiscard]] int getCardsBeingLookedAt() const
68 {
69 return cardsBeingLookedAt;
70 }
71 void setCardsBeingLookedAt(int _cardsBeingLookedAt)
72 {
73 cardsBeingLookedAt = qMax(0, _cardsBeingLookedAt);
74 }
75 [[nodiscard]] bool isCardAtPosLookedAt(int pos) const;
76 [[nodiscard]] bool hasCoords() const
77 {
78 return has_coords;
79 }
80 [[nodiscard]] ServerInfo_Zone::ZoneType getType() const
81 {
82 return type;
83 }
84 [[nodiscard]] QString getName() const
85 {
86 return name;
87 }
88 [[nodiscard]] Server_AbstractPlayer *getPlayer() const
89 {
90 return player;
91 }
92 void getInfo(ServerInfo_Zone *info, Server_AbstractParticipant *recipient, bool omniscient);
93
94 [[nodiscard]] int getFreeGridColumn(int x, int y, const QString &cardName, bool dontStackSameName) const;
95 [[nodiscard]] bool isColumnEmpty(int x, int y) const;
96 [[nodiscard]] bool isColumnStacked(int x, int y) const;
98 void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
99 void insertCard(Server_Card *card, int x, int y);
100 void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
101 void shuffle(int start = 0, int end = -1);
102 void clear();
103 void addWritePermission(int playerId);
104 [[nodiscard]] const QSet<int> &getPlayersWithWritePermission() const
105 {
107 }
108 [[nodiscard]] bool getAlwaysRevealTopCard() const
109 {
110 return alwaysRevealTopCard;
111 }
112 void setAlwaysRevealTopCard(bool _alwaysRevealTopCard)
113 {
114 alwaysRevealTopCard = _alwaysRevealTopCard;
115 }
116 [[nodiscard]] bool getAlwaysLookAtTopCard() const
117 {
118 return alwaysLookAtTopCard;
119 }
120 void setAlwaysLookAtTopCard(bool _alwaysLookAtTopCard)
121 {
122 alwaysLookAtTopCard = _alwaysLookAtTopCard;
123 }
124};
125
126#endif
Definition server_response_containers.h:46
Definition server_abstract_participant.h:57
Definition server_abstract_player.h:19
void clear()
Definition server_cardzone.cpp:304
~Server_CardZone()
Definition server_cardzone.cpp:39
bool alwaysRevealTopCard
Definition server_cardzone.h:43
Server_AbstractPlayer * player
Definition server_cardzone.h:37
bool isCardAtPosLookedAt(int pos) const
Definition server_cardzone.cpp:177
bool has_coords
Definition server_cardzone.h:39
QString name
Definition server_cardzone.h:38
const QSet< int > & getPlayersWithWritePermission() const
Definition server_cardzone.h:104
QSet< int > playersWithWritePermission
Definition server_cardzone.h:42
ServerInfo_Zone::ZoneType getType() const
Definition server_cardzone.h:80
void insertCard(Server_Card *card, int x, int y)
Definition server_cardzone.cpp:287
int removeCard(Server_Card *card)
Definition server_cardzone.cpp:125
void setAlwaysLookAtTopCard(bool _alwaysLookAtTopCard)
Definition server_cardzone.h:120
bool getAlwaysLookAtTopCard() const
Definition server_cardzone.h:116
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard)
Definition server_cardzone.h:112
void shuffle(int start=0, int end=-1)
Definition server_cardzone.cpp:45
Server_Card * getCard(int id, int *position=nullptr, bool remove=false)
Definition server_cardzone.cpp:147
void getInfo(ServerInfo_Zone *info, Server_AbstractParticipant *recipient, bool omniscient)
Definition server_cardzone.cpp:321
void insertCardIntoCoordMap(Server_Card *card, int x, int y)
Definition server_cardzone.cpp:102
bool isColumnStacked(int x, int y) const
Definition server_cardzone.cpp:224
int getCardsBeingLookedAt() const
Definition server_cardzone.h:67
const QList< Server_Card * > & getCards() const
Definition server_cardzone.h:59
int cardsBeingLookedAt
Definition server_cardzone.h:41
int getFreeGridColumn(int x, int y, const QString &cardName, bool dontStackSameName) const
Definition server_cardzone.cpp:182
QMap< int, QMap< int, Server_Card * > > coordinateMap
Definition server_cardzone.h:46
QString getName() const
Definition server_cardzone.h:84
Server_AbstractPlayer * getPlayer() const
Definition server_cardzone.h:88
void addWritePermission(int playerId)
Definition server_cardzone.cpp:316
bool getAlwaysRevealTopCard() const
Definition server_cardzone.h:108
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y)
Definition server_cardzone.cpp:240
void fixFreeSpaces(GameEventStorage &ges)
Definition server_cardzone.cpp:248
QMap< int, int > freeSpaceMap
Definition server_cardzone.h:48
bool alwaysLookAtTopCard
Definition server_cardzone.h:44
void setCardsBeingLookedAt(int _cardsBeingLookedAt)
Definition server_cardzone.h:71
QMap< int, QMultiMap< QString, int > > freePilesMap
Definition server_cardzone.h:47
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY)
Definition server_cardzone.cpp:75
bool hasCoords() const
Definition server_cardzone.h:76
void updateCardCoordinates(Server_Card *card, int oldX, int oldY)
Definition server_cardzone.cpp:277
Server_CardZone(Server_AbstractPlayer *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type)
Definition server_cardzone.cpp:30
ServerInfo_Zone::ZoneType type
Definition server_cardzone.h:40
QList< Server_Card * > cards
Definition server_cardzone.h:45
bool isColumnEmpty(int x, int y) const
Definition server_cardzone.cpp:232
Definition server_card.h:36
Definition server_game.h:47