Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
4e8ba699
Commit
4e8ba699
authored
Jul 08, 2014
by
arxanas
Browse files
Tabs to spaces.
parent
1217689e
Changes
38
Expand all
Hide whitespace changes
Inline
Side-by-side
common/color.h
View file @
4e8ba699
...
...
@@ -10,26 +10,26 @@
#ifdef QT_GUI_LIB
inline
QColor
convertColorToQColor
(
const
color
&
c
)
{
return
QColor
(
c
.
r
(),
c
.
g
(),
c
.
b
());
return
QColor
(
c
.
r
(),
c
.
g
(),
c
.
b
());
}
inline
color
convertQColorToColor
(
const
QColor
&
c
)
{
color
result
;
result
.
set_r
(
c
.
red
());
result
.
set_g
(
c
.
green
());
result
.
set_b
(
c
.
blue
());
return
result
;
color
result
;
result
.
set_r
(
c
.
red
());
result
.
set_g
(
c
.
green
());
result
.
set_b
(
c
.
blue
());
return
result
;
}
#endif
inline
color
makeColor
(
int
r
,
int
g
,
int
b
)
{
color
result
;
result
.
set_r
(
r
);
result
.
set_g
(
g
);
result
.
set_b
(
b
);
return
result
;
color
result
;
result
.
set_r
(
r
);
result
.
set_g
(
g
);
result
.
set_b
(
b
);
return
result
;
}
#endif
common/decklist.cpp
View file @
4e8ba699
This diff is collapsed.
Click to expand it.
common/decklist.h
View file @
4e8ba699
...
...
@@ -23,152 +23,152 @@ class InnerDecklistNode;
class
SideboardPlan
{
private:
QString
name
;
QList
<
MoveCard_ToZone
>
moveList
;
QString
name
;
QList
<
MoveCard_ToZone
>
moveList
;
public:
SideboardPlan
(
const
QString
&
_name
=
QString
(),
const
QList
<
MoveCard_ToZone
>
&
_moveList
=
QList
<
MoveCard_ToZone
>
());
bool
readElement
(
QXmlStreamReader
*
xml
);
void
write
(
QXmlStreamWriter
*
xml
);
SideboardPlan
(
const
QString
&
_name
=
QString
(),
const
QList
<
MoveCard_ToZone
>
&
_moveList
=
QList
<
MoveCard_ToZone
>
());
bool
readElement
(
QXmlStreamReader
*
xml
);
void
write
(
QXmlStreamWriter
*
xml
);
QString
getName
()
const
{
return
name
;
}
const
QList
<
MoveCard_ToZone
>
&
getMoveList
()
const
{
return
moveList
;
}
void
setMoveList
(
const
QList
<
MoveCard_ToZone
>
&
_moveList
);
QString
getName
()
const
{
return
name
;
}
const
QList
<
MoveCard_ToZone
>
&
getMoveList
()
const
{
return
moveList
;
}
void
setMoveList
(
const
QList
<
MoveCard_ToZone
>
&
_moveList
);
};
enum
DeckSortMethod
{
ByNumber
,
ByName
,
ByPrice
};
class
AbstractDecklistNode
{
protected:
InnerDecklistNode
*
parent
;
DeckSortMethod
sortMethod
;
InnerDecklistNode
*
parent
;
DeckSortMethod
sortMethod
;
public:
AbstractDecklistNode
(
InnerDecklistNode
*
_parent
=
0
);
virtual
~
AbstractDecklistNode
()
{
}
virtual
void
setSortMethod
(
DeckSortMethod
method
)
{
sortMethod
=
method
;
}
virtual
QString
getName
()
const
=
0
;
InnerDecklistNode
*
getParent
()
const
{
return
parent
;
}
int
depth
()
const
;
virtual
int
height
()
const
=
0
;
virtual
bool
compare
(
AbstractDecklistNode
*
other
)
const
=
0
;
virtual
bool
readElement
(
QXmlStreamReader
*
xml
)
=
0
;
virtual
void
writeElement
(
QXmlStreamWriter
*
xml
)
=
0
;
AbstractDecklistNode
(
InnerDecklistNode
*
_parent
=
0
);
virtual
~
AbstractDecklistNode
()
{
}
virtual
void
setSortMethod
(
DeckSortMethod
method
)
{
sortMethod
=
method
;
}
virtual
QString
getName
()
const
=
0
;
InnerDecklistNode
*
getParent
()
const
{
return
parent
;
}
int
depth
()
const
;
virtual
int
height
()
const
=
0
;
virtual
bool
compare
(
AbstractDecklistNode
*
other
)
const
=
0
;
virtual
bool
readElement
(
QXmlStreamReader
*
xml
)
=
0
;
virtual
void
writeElement
(
QXmlStreamWriter
*
xml
)
=
0
;
};
class
InnerDecklistNode
:
public
AbstractDecklistNode
,
public
QList
<
AbstractDecklistNode
*>
{
private:
QString
name
;
class
compareFunctor
;
QString
name
;
class
compareFunctor
;
public:
InnerDecklistNode
(
const
QString
&
_name
=
QString
(),
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
),
name
(
_name
)
{
}
InnerDecklistNode
(
InnerDecklistNode
*
other
,
InnerDecklistNode
*
_parent
=
0
);
virtual
~
InnerDecklistNode
();
void
setSortMethod
(
DeckSortMethod
method
);
QString
getName
()
const
{
return
name
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
static
QString
visibleNameFromName
(
const
QString
&
_name
);
virtual
QString
getVisibleName
()
const
;
void
clearTree
();
AbstractDecklistNode
*
findChild
(
const
QString
&
name
);
int
height
()
const
;
int
recursiveCount
(
bool
countTotalCards
=
false
)
const
;
InnerDecklistNode
(
const
QString
&
_name
=
QString
(),
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
),
name
(
_name
)
{
}
InnerDecklistNode
(
InnerDecklistNode
*
other
,
InnerDecklistNode
*
_parent
=
0
);
virtual
~
InnerDecklistNode
();
void
setSortMethod
(
DeckSortMethod
method
);
QString
getName
()
const
{
return
name
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
static
QString
visibleNameFromName
(
const
QString
&
_name
);
virtual
QString
getVisibleName
()
const
;
void
clearTree
();
AbstractDecklistNode
*
findChild
(
const
QString
&
name
);
int
height
()
const
;
int
recursiveCount
(
bool
countTotalCards
=
false
)
const
;
float
recursivePrice
(
bool
countTotalCards
=
false
)
const
;
bool
compare
(
AbstractDecklistNode
*
other
)
const
;
bool
compareNumber
(
AbstractDecklistNode
*
other
)
const
;
bool
compareName
(
AbstractDecklistNode
*
other
)
const
;
bool
comparePrice
(
AbstractDecklistNode
*
other
)
const
;
QVector
<
QPair
<
int
,
int
>
>
sort
(
Qt
::
SortOrder
order
=
Qt
::
AscendingOrder
);
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
bool
compare
(
AbstractDecklistNode
*
other
)
const
;
bool
compareNumber
(
AbstractDecklistNode
*
other
)
const
;
bool
compareName
(
AbstractDecklistNode
*
other
)
const
;
bool
comparePrice
(
AbstractDecklistNode
*
other
)
const
;
QVector
<
QPair
<
int
,
int
>
>
sort
(
Qt
::
SortOrder
order
=
Qt
::
AscendingOrder
);
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
AbstractDecklistCardNode
:
public
AbstractDecklistNode
{
public:
AbstractDecklistCardNode
(
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
)
{
}
virtual
int
getNumber
()
const
=
0
;
virtual
void
setNumber
(
int
_number
)
=
0
;
virtual
QString
getName
()
const
=
0
;
virtual
void
setName
(
const
QString
&
_name
)
=
0
;
AbstractDecklistCardNode
(
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
)
{
}
virtual
int
getNumber
()
const
=
0
;
virtual
void
setNumber
(
int
_number
)
=
0
;
virtual
QString
getName
()
const
=
0
;
virtual
void
setName
(
const
QString
&
_name
)
=
0
;
virtual
float
getPrice
()
const
=
0
;
virtual
void
setPrice
(
const
float
_price
)
=
0
;
float
getTotalPrice
()
const
{
return
getNumber
()
*
getPrice
();
}
int
height
()
const
{
return
0
;
}
bool
compare
(
AbstractDecklistNode
*
other
)
const
;
bool
compareNumber
(
AbstractDecklistNode
*
other
)
const
;
bool
compareName
(
AbstractDecklistNode
*
other
)
const
;
bool
compareTotalPrice
(
AbstractDecklistNode
*
other
)
const
;
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
int
height
()
const
{
return
0
;
}
bool
compare
(
AbstractDecklistNode
*
other
)
const
;
bool
compareNumber
(
AbstractDecklistNode
*
other
)
const
;
bool
compareName
(
AbstractDecklistNode
*
other
)
const
;
bool
compareTotalPrice
(
AbstractDecklistNode
*
other
)
const
;
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
DecklistCardNode
:
public
AbstractDecklistCardNode
{
private:
QString
name
;
int
number
;
QString
name
;
int
number
;
float
price
;
public:
DecklistCardNode
(
const
QString
&
_name
=
QString
(),
int
_number
=
1
,
float
_price
=
0
,
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistCardNode
(
_parent
),
name
(
_name
),
number
(
_number
),
price
(
_price
)
{
}
DecklistCardNode
(
const
QString
&
_name
=
QString
(),
int
_number
=
1
,
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistCardNode
(
_parent
),
name
(
_name
),
number
(
_number
),
price
(
0
)
{
}
DecklistCardNode
(
DecklistCardNode
*
other
,
InnerDecklistNode
*
_parent
);
int
getNumber
()
const
{
return
number
;
}
void
setNumber
(
int
_number
)
{
number
=
_number
;
}
QString
getName
()
const
{
return
name
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
DecklistCardNode
(
DecklistCardNode
*
other
,
InnerDecklistNode
*
_parent
);
int
getNumber
()
const
{
return
number
;
}
void
setNumber
(
int
_number
)
{
number
=
_number
;
}
QString
getName
()
const
{
return
name
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
float
getPrice
()
const
{
return
price
;
}
void
setPrice
(
const
float
_price
)
{
price
=
_price
;
}
};
class
DeckList
:
public
QObject
{
Q_OBJECT
Q_OBJECT
private:
QString
name
,
comments
;
QString
deckHash
;
QMap
<
QString
,
SideboardPlan
*>
sideboardPlans
;
InnerDecklistNode
*
root
;
void
getCardListHelper
(
InnerDecklistNode
*
node
,
QSet
<
QString
>
&
result
)
const
;
QString
name
,
comments
;
QString
deckHash
;
QMap
<
QString
,
SideboardPlan
*>
sideboardPlans
;
InnerDecklistNode
*
root
;
void
getCardListHelper
(
InnerDecklistNode
*
node
,
QSet
<
QString
>
&
result
)
const
;
signals:
void
deckHashChanged
();
void
deckHashChanged
();
public
slots
:
void
setName
(
const
QString
&
_name
=
QString
())
{
name
=
_name
;
}
void
setComments
(
const
QString
&
_comments
=
QString
())
{
comments
=
_comments
;
}
void
setName
(
const
QString
&
_name
=
QString
())
{
name
=
_name
;
}
void
setComments
(
const
QString
&
_comments
=
QString
())
{
comments
=
_comments
;
}
public:
DeckList
();
DeckList
(
const
DeckList
&
other
);
DeckList
(
const
QString
&
nativeString
);
~
DeckList
();
QString
getName
()
const
{
return
name
;
}
QString
getComments
()
const
{
return
comments
;
}
QList
<
MoveCard_ToZone
>
getCurrentSideboardPlan
();
void
setCurrentSideboardPlan
(
const
QList
<
MoveCard_ToZone
>
&
plan
);
const
QMap
<
QString
,
SideboardPlan
*>
&
getSideboardPlans
()
const
{
return
sideboardPlans
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
write
(
QXmlStreamWriter
*
xml
);
bool
loadFromXml
(
QXmlStreamReader
*
xml
);
bool
loadFromString_Native
(
const
QString
&
nativeString
);
QString
writeToString_Native
();
bool
loadFromFile_Native
(
QIODevice
*
device
);
bool
saveToFile_Native
(
QIODevice
*
device
);
bool
loadFromStream_Plain
(
QTextStream
&
stream
);
bool
loadFromFile_Plain
(
QIODevice
*
device
);
bool
saveToStream_Plain
(
QTextStream
&
stream
);
bool
saveToFile_Plain
(
QIODevice
*
device
);
QString
writeToString_Plain
();
void
cleanList
();
bool
isEmpty
()
const
{
return
root
->
isEmpty
()
&&
name
.
isEmpty
()
&&
comments
.
isEmpty
()
&&
sideboardPlans
.
isEmpty
();
}
QStringList
getCardList
()
const
;
DeckList
();
DeckList
(
const
DeckList
&
other
);
DeckList
(
const
QString
&
nativeString
);
~
DeckList
();
QString
getName
()
const
{
return
name
;
}
QString
getComments
()
const
{
return
comments
;
}
QList
<
MoveCard_ToZone
>
getCurrentSideboardPlan
();
void
setCurrentSideboardPlan
(
const
QList
<
MoveCard_ToZone
>
&
plan
);
const
QMap
<
QString
,
SideboardPlan
*>
&
getSideboardPlans
()
const
{
return
sideboardPlans
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
write
(
QXmlStreamWriter
*
xml
);
bool
loadFromXml
(
QXmlStreamReader
*
xml
);
bool
loadFromString_Native
(
const
QString
&
nativeString
);
QString
writeToString_Native
();
bool
loadFromFile_Native
(
QIODevice
*
device
);
bool
saveToFile_Native
(
QIODevice
*
device
);
bool
loadFromStream_Plain
(
QTextStream
&
stream
);
bool
loadFromFile_Plain
(
QIODevice
*
device
);
bool
saveToStream_Plain
(
QTextStream
&
stream
);
bool
saveToFile_Plain
(
QIODevice
*
device
);
QString
writeToString_Plain
();
void
cleanList
();
bool
isEmpty
()
const
{
return
root
->
isEmpty
()
&&
name
.
isEmpty
()
&&
comments
.
isEmpty
()
&&
sideboardPlans
.
isEmpty
();
}
QStringList
getCardList
()
const
;
int
getSideboardSize
()
const
;
QString
getDeckHash
()
const
{
return
deckHash
;
}
void
updateDeckHash
();
QString
getDeckHash
()
const
{
return
deckHash
;
}
void
updateDeckHash
();
InnerDecklistNode
*
getRoot
()
const
{
return
root
;
}
DecklistCardNode
*
addCard
(
const
QString
&
cardName
,
const
QString
&
zoneName
);
bool
deleteNode
(
AbstractDecklistNode
*
node
,
InnerDecklistNode
*
rootNode
=
0
);
InnerDecklistNode
*
getRoot
()
const
{
return
root
;
}
DecklistCardNode
*
addCard
(
const
QString
&
cardName
,
const
QString
&
zoneName
);
bool
deleteNode
(
AbstractDecklistNode
*
node
,
InnerDecklistNode
*
rootNode
=
0
);
};
#endif
common/get_pb_extension.cpp
View file @
4e8ba699
...
...
@@ -4,10 +4,10 @@
int
getPbExtension
(
const
::
google
::
protobuf
::
Message
&
message
)
{
std
::
vector
<
const
::
google
::
protobuf
::
FieldDescriptor
*
>
fieldList
;
message
.
GetReflection
()
->
ListFields
(
message
,
&
fieldList
);
for
(
unsigned
int
j
=
0
;
j
<
fieldList
.
size
();
++
j
)
if
(
fieldList
[
j
]
->
is_extension
())
return
fieldList
[
j
]
->
number
();
return
-
1
;
std
::
vector
<
const
::
google
::
protobuf
::
FieldDescriptor
*
>
fieldList
;
message
.
GetReflection
()
->
ListFields
(
message
,
&
fieldList
);
for
(
unsigned
int
j
=
0
;
j
<
fieldList
.
size
();
++
j
)
if
(
fieldList
[
j
]
->
is_extension
())
return
fieldList
[
j
]
->
number
();
return
-
1
;
}
common/get_pb_extension.h
View file @
4e8ba699
...
...
@@ -2,9 +2,9 @@
#define GET_PB_EXTENSION_H
namespace
google
{
namespace
protobuf
{
class
Message
;
}
namespace
protobuf
{
class
Message
;
}
}
int
getPbExtension
(
const
::
google
::
protobuf
::
Message
&
message
);
...
...
common/rng_abstract.cpp
View file @
4e8ba699
...
...
@@ -4,27 +4,27 @@
QVector
<
int
>
RNG_Abstract
::
makeNumbersVector
(
int
n
,
int
min
,
int
max
)
{
const
int
bins
=
max
-
min
+
1
;
QVector
<
int
>
result
(
bins
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
int
number
=
rand
(
min
,
max
);
if
((
number
<
min
)
||
(
number
>
max
))
qDebug
()
<<
"rand("
<<
min
<<
","
<<
max
<<
") returned "
<<
number
;
else
result
[
number
-
min
]
++
;
}
return
result
;
const
int
bins
=
max
-
min
+
1
;
QVector
<
int
>
result
(
bins
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
int
number
=
rand
(
min
,
max
);
if
((
number
<
min
)
||
(
number
>
max
))
qDebug
()
<<
"rand("
<<
min
<<
","
<<
max
<<
") returned "
<<
number
;
else
result
[
number
-
min
]
++
;
}
return
result
;
}
double
RNG_Abstract
::
testRandom
(
const
QVector
<
int
>
&
numbers
)
const
{
int
n
=
0
;
for
(
int
i
=
0
;
i
<
numbers
.
size
();
++
i
)
n
+=
numbers
[
i
];
double
expected
=
(
double
)
n
/
(
double
)
numbers
.
size
();
double
chisq
=
0
;
for
(
int
i
=
0
;
i
<
numbers
.
size
();
++
i
)
chisq
+=
((
double
)
numbers
[
i
]
-
expected
)
*
((
double
)
numbers
[
i
]
-
expected
)
/
expected
;
return
chisq
;
int
n
=
0
;
for
(
int
i
=
0
;
i
<
numbers
.
size
();
++
i
)
n
+=
numbers
[
i
];
double
expected
=
(
double
)
n
/
(
double
)
numbers
.
size
();
double
chisq
=
0
;
for
(
int
i
=
0
;
i
<
numbers
.
size
();
++
i
)
chisq
+=
((
double
)
numbers
[
i
]
-
expected
)
*
((
double
)
numbers
[
i
]
-
expected
)
/
expected
;
return
chisq
;
}
common/rng_abstract.h
View file @
4e8ba699
...
...
@@ -5,12 +5,12 @@
#include
<QVector>
class
RNG_Abstract
:
public
QObject
{
Q_OBJECT
Q_OBJECT
public:
RNG_Abstract
(
QObject
*
parent
=
0
)
:
QObject
(
parent
)
{
}
virtual
unsigned
int
rand
(
int
min
,
int
max
)
=
0
;
QVector
<
int
>
makeNumbersVector
(
int
n
,
int
min
,
int
max
);
double
testRandom
(
const
QVector
<
int
>
&
numbers
)
const
;
RNG_Abstract
(
QObject
*
parent
=
0
)
:
QObject
(
parent
)
{
}
virtual
unsigned
int
rand
(
int
min
,
int
max
)
=
0
;
QVector
<
int
>
makeNumbersVector
(
int
n
,
int
min
,
int
max
);
double
testRandom
(
const
QVector
<
int
>
&
numbers
)
const
;
};
extern
RNG_Abstract
*
rng
;
...
...
common/rng_sfmt.cpp
View file @
4e8ba699
...
...
@@ -11,10 +11,10 @@
#endif
RNG_SFMT
::
RNG_SFMT
(
QObject
*
parent
)
:
RNG_Abstract
(
parent
)
:
RNG_Abstract
(
parent
)
{
// initialize the random number generator with a 32bit integer seed (timestamp)
sfmt_init_gen_rand
(
&
sfmt
,
QDateTime
::
currentDateTime
().
toTime_t
());
// initialize the random number generator with a 32bit integer seed (timestamp)
sfmt_init_gen_rand
(
&
sfmt
,
QDateTime
::
currentDateTime
().
toTime_t
());
}
/**
...
...
@@ -32,11 +32,11 @@ unsigned int RNG_SFMT::rand(int min, int max) {
* There has been no use for negative random numbers with rand() though, so it's treated as error.
*/
if
(
min
<
0
)
{
throw
std
::
invalid_argument
(
QString
(
"Invalid bounds for RNG: Got min "
+
QString
::
number
(
min
)
+
" < 0!
\n
"
).
toStdString
());
// at this point, the method exits. No return value is needed, because
// basically the exception itself is returned.
throw
std
::
invalid_argument
(
QString
(
"Invalid bounds for RNG: Got min "
+
QString
::
number
(
min
)
+
" < 0!
\n
"
).
toStdString
());
// at this point, the method exits. No return value is needed, because
// basically the exception itself is returned.
}
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
...
...
@@ -99,38 +99,38 @@ unsigned int RNG_SFMT::rand(int min, int max) {
*/
unsigned
int
RNG_SFMT
::
cdf
(
unsigned
int
min
,
unsigned
int
max
)
{
// This all makes no sense if min > max, which should never happen.
if
(
min
>
max
)
{
throw
std
::
invalid_argument
(
QString
(
"Invalid bounds for RNG: min > max! Values were: min = "
+
QString
::
number
(
min
)
+
", max = "
+
QString
::
number
(
max
)).
toStdString
());
// at this point, the method exits. No return value is needed, because
// basically the exception itself is returned.
}
// This all makes no sense if min > max, which should never happen.
if
(
min
>
max
)
{
throw
std
::
invalid_argument
(
QString
(
"Invalid bounds for RNG: min > max! Values were: min = "
+
QString
::
number
(
min
)
+
", max = "
+
QString
::
number
(
max
)).
toStdString
());
// at this point, the method exits. No return value is needed, because
// basically the exception itself is returned.
}
// First compute the diameter (aka size, length) of the [min, max] interval
const
unsigned
int
diameter
=
max
-
min
+
1
;
// First compute the diameter (aka size, length) of the [min, max] interval
const
unsigned
int
diameter
=
max
-
min
+
1
;
// Compute how many buckets (each in size of the diameter) will fit into the
// universe.
// If the division has a remainder, the result is floored automatically.
const
uint64_t
buckets
=
UINT64_MAX
/
diameter
;
// Compute how many buckets (each in size of the diameter) will fit into the
// universe.
// If the division has a remainder, the result is floored automatically.
const
uint64_t
buckets
=
UINT64_MAX
/
diameter
;
// Compute the last valid random number. All numbers beyond have to be ignored.
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
const
uint64_t
limit
=
diameter
*
buckets
;
// Compute the last valid random number. All numbers beyond have to be ignored.
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
const
uint64_t
limit
=
diameter
*
buckets
;
uint64_t
rand
;
// To make the random number generation thread-safe, a mutex is created around
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
mutex
.
lock
();
do
{
rand
=
sfmt_genrand_uint64
(
&
sfmt
);
}
while
(
rand
>=
limit
);
mutex
.
unlock
();
uint64_t
rand
;
// To make the random number generation thread-safe, a mutex is created around
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
mutex
.
lock
();
do
{
rand
=
sfmt_genrand_uint64
(
&
sfmt
);
}
while
(
rand
>=
limit
);
mutex
.
unlock
();
// Now determine the bucket containing the SFMT() random number and after adding
// the lower bound, a random number from [min, max] can be returned.
return
(
unsigned
int
)
(
rand
/
buckets
+
min
);
// Now determine the bucket containing the SFMT() random number and after adding
// the lower bound, a random number from [min, max] can be returned.
return
(
unsigned
int
)
(
rand
/
buckets
+
min
);
}
common/rng_sfmt.h
View file @
4e8ba699
...
...
@@ -26,15 +26,15 @@
*/
class
RNG_SFMT
:
public
RNG_Abstract
{
Q_OBJECT
Q_OBJECT
private:
QMutex
mutex
;
sfmt_t
sfmt
;
// The discrete cumulative distribution function for the RNG
unsigned
int
cdf
(
unsigned
int
min
,
unsigned
int
max
);
QMutex
mutex
;
sfmt_t
sfmt
;
// The discrete cumulative distribution function for the RNG
unsigned
int
cdf
(
unsigned
int
min
,
unsigned
int
max
);
public:
RNG_SFMT
(
QObject
*
parent
=
0
);
unsigned
int
rand
(
int
min
,
int
max
);
RNG_SFMT
(
QObject
*
parent
=
0
);
unsigned
int
rand
(
int
min
,
int
max
);
};
#endif
...
...
common/server.cpp
View file @
4e8ba699
This diff is collapsed.
Click to expand it.
common/server.h
View file @
4e8ba699
...
...
@@ -31,87 +31,87 @@ enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2,
class
Server
:
public
QObject
{
Q_OBJECT
Q_OBJECT
signals:
void
pingClockTimeout
();
void
sigSendIslMessage
(
const
IslMessage
&
message
,
int
serverId
);
void
endSession
(
qint64
sessionId
);
void
pingClockTimeout
();
void
sigSendIslMessage
(
const
IslMessage
&
message
,
int
serverId
);
void
endSession
(
qint64
sessionId
);
private
slots
:
void
broadcastRoomUpdate
(
const
ServerInfo_Room
&
roomInfo
,
bool
sendToIsl
=
false
);
void
broadcastRoomUpdate
(
const
ServerInfo_Room
&
roomInfo
,
bool
sendToIsl
=
false
);
public:
mutable
QReadWriteLock
clientsLock
,
roomsLock
;
// locking order: roomsLock before clientsLock
Server
(
bool
_threaded
,
QObject
*
parent
=
0
);
~
Server
();
void
setThreaded
(
bool
_threaded
)
{
threaded
=
_threaded
;
}
AuthenticationResult
loginUser
(
Server_ProtocolHandler
*
session
,
QString
&
name
,
const
QString
&
password
,
QString
&
reason
,
int
&
secondsLeft
);
const
QMap
<
int
,
Server_Room
*>
&
getRooms
()
{
return
rooms
;
}
Server_AbstractUserInterface
*
findUser
(
const
QString
&
userName
)
const
;
const
QMap
<
QString
,
Server_ProtocolHandler
*>
&
getUsers
()
const
{
return
users
;
}
const
QMap
<
qint64
,
Server_ProtocolHandler
*>
&
getUsersBySessionId
()
const
{
return
usersBySessionId
;
}
void
addClient
(
Server_ProtocolHandler
*
player
);
void
removeClient
(
Server_ProtocolHandler
*
player
);
virtual
QString
getLoginMessage
()
const
{
return
QString
();
}
virtual
bool
getGameShouldPing
()
const
{
return
false
;
}
virtual
int
getMaxGameInactivityTime
()
const
{
return
9999999
;
}
virtual
int
getMaxPlayerInactivityTime
()
const
{
return
9999999
;
}
virtual
int
getMessageCountingInterval
()
const
{
return
0
;
}
virtual
int
getMaxMessageCountPerInterval
()
const
{
return
0
;
}
virtual
int
getMaxMessageSizePerInterval
()
const
{
return
0
;
}
virtual
int
getMaxGamesPerUser
()
const
{
return
0
;
}
virtual
bool
getThreaded
()
const
{
return
false
;
}
Server_DatabaseInterface
*
getDatabaseInterface
()
const
;
int
getNextLocalGameId
()
{
QMutexLocker
locker
(
&
nextLocalGameIdMutex
);
return
++
nextLocalGameId
;
}
void
sendIsl_Response
(
const
Response
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_SessionEvent
(
const
SessionEvent
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_GameEventContainer
(
const
GameEventContainer
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_RoomEvent
(
const
RoomEvent
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_GameCommand
(
const
CommandContainer
&
item
,
int
serverId
,
qint64
sessionId
,
int
roomId
,
int
playerId
);
void
sendIsl_RoomCommand
(
const
CommandContainer
&
item
,
int
serverId
,
qint64
sessionId
,
int
roomId
);
void
addExternalUser
(
const
ServerInfo_User
&
userInfo
);
void
removeExternalUser
(
const
QString
&
userName
);
const
QMap
<
QString
,
Server_AbstractUserInterface
*>
&
getExternalUsers
()
const
{
return
externalUsers
;
}
void
addPersistentPlayer
(
const
QString
&
userName
,
int
roomId
,
int
gameId
,
int
playerId
);
void
removePersistentPlayer
(
const
QString
&
userName
,
int
roomId
,
int
gameId
,
int
playerId
);
QList
<
PlayerReference
>
getPersistentPlayerReferences
(
const
QString
&
userName
)
const
;
mutable
QReadWriteLock
clientsLock
,
roomsLock
;
// locking order: roomsLock before clientsLock
Server
(
bool
_threaded
,
QObject
*
parent
=
0
);
~
Server
();
void
setThreaded
(
bool
_threaded
)
{
threaded
=
_threaded
;
}
AuthenticationResult
loginUser
(
Server_ProtocolHandler
*
session
,
QString
&
name
,
const
QString
&
password
,
QString
&
reason
,
int
&
secondsLeft
);
const
QMap
<
int
,
Server_Room
*>
&
getRooms
()
{
return
rooms
;
}
Server_AbstractUserInterface
*
findUser
(
const
QString
&
userName
)
const
;
const
QMap
<
QString
,
Server_ProtocolHandler
*>
&
getUsers
()
const
{
return
users
;
}
const
QMap
<
qint64
,
Server_ProtocolHandler
*>
&
getUsersBySessionId
()
const
{
return
usersBySessionId
;
}
void
addClient
(
Server_ProtocolHandler
*
player
);
void
removeClient
(
Server_ProtocolHandler
*
player
);
virtual
QString
getLoginMessage
()
const
{
return
QString
();
}
virtual
bool
getGameShouldPing
()
const
{
return
false
;
}
virtual
int
getMaxGameInactivityTime
()
const
{
return
9999999
;
}
virtual
int
getMaxPlayerInactivityTime
()
const
{
return
9999999
;
}
virtual
int
getMessageCountingInterval
()
const
{
return
0
;
}
virtual
int
getMaxMessageCountPerInterval
()
const
{
return
0
;
}
virtual
int
getMaxMessageSizePerInterval
()
const
{
return
0
;
}
virtual
int
getMaxGamesPerUser
()
const
{
return
0
;
}
virtual
bool
getThreaded
()
const
{
return
false
;
}
Server_DatabaseInterface
*
getDatabaseInterface
()
const
;
int
getNextLocalGameId
()
{
QMutexLocker
locker
(
&
nextLocalGameIdMutex
);
return
++
nextLocalGameId
;
}
void
sendIsl_Response
(
const
Response
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_SessionEvent
(
const
SessionEvent
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_GameEventContainer
(
const
GameEventContainer
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_RoomEvent
(
const
RoomEvent
&
item
,
int
serverId
=
-
1
,
qint64
sessionId
=
-
1
);
void
sendIsl_GameCommand
(
const
CommandContainer
&
item
,
int
serverId
,
qint64
sessionId
,
int
roomId
,
int
playerId
);
void
sendIsl_RoomCommand
(
const
CommandContainer
&
item
,
int
serverId
,
qint64
sessionId
,
int
roomId
);
void
addExternalUser
(
const
ServerInfo_User
&
userInfo
);
void
removeExternalUser
(
const
QString
&
userName
);
const
QMap
<
QString
,
Server_AbstractUserInterface
*>
&
getExternalUsers
()
const
{
return
externalUsers
;
}
void
addPersistentPlayer
(
const
QString
&
userName
,
int
roomId
,
int
gameId
,
int
playerId
);
void
removePersistentPlayer
(
const
QString
&
userName
,
int
roomId
,
int
gameId
,
int
playerId
);
QList
<
PlayerReference
>
getPersistentPlayerReferences
(
const
QString
&
userName
)
const
;
private:
bool
threaded
;
QMultiMap
<
QString
,
PlayerReference
>
persistentPlayers
;
mutable
QReadWriteLock
persistentPlayersLock
;
int
nextLocalGameId
;
QMutex
nextLocalGameIdMutex
;
protected
slots
:
void
externalUserJoined
(
const
ServerInfo_User
&
userInfo
);
void
externalUserLeft
(
const
QString
&
userName
);
void
externalRoomUserJoined
(
int
roomId
,
const
ServerInfo_User
&
userInfo
);
void
externalRoomUserLeft
(
int
roomId
,
const
QString
&
userName
);
void
externalRoomSay
(
int
roomId
,
const
QString
&
userName
,
const
QString
&
message
);
void
externalRoomGameListChanged
(
int
roomId
,
const
ServerInfo_Game
&
gameInfo
);
void
externalJoinGameCommandReceived
(
const
Command_JoinGame
&
cmd
,
int
cmdId
,
int
roomId
,
int
serverId
,
qint64
sessionId
);
void
externalGameCommandContainerReceived
(
const
CommandContainer
&
cont
,
int
playerId
,
int
serverId
,
qint64
sessionId
);
void
externalGameEventContainerReceived
(
const
GameEventContainer
&
cont
,
qint64
sessionId
);
void
externalResponseReceived
(
const
Response
&
resp
,
qint64
sessionId
);
virtual
void
doSendIslMessage
(
const
IslMessage
&
msg
,
int
serverId
)
{
}
bool
threaded
;
QMultiMap
<
QString
,
PlayerReference
>
persistentPlayers
;
mutable
QReadWriteLock
persistentPlayersLock
;
int
nextLocalGameId
;
QMutex
nextLocalGameIdMutex
;
protected
slots
:
void
externalUserJoined
(
const
ServerInfo_User
&
userInfo
);
void
externalUserLeft
(
const
QString
&
userName
);
void
externalRoomUserJoined
(
int
roomId
,
const
ServerInfo_User
&
userInfo
);
void
externalRoomUserLeft
(
int
roomId
,
const
QString
&
userName
);
void
externalRoomSay
(
int
roomId
,
const
QString
&
userName
,
const
QString
&
message
);
void
externalRoomGameListChanged
(
int
roomId
,
const
ServerInfo_Game
&
gameInfo
);
void
externalJoinGameCommandReceived
(
const
Command_JoinGame
&
cmd
,
int
cmdId
,
int
roomId
,
int
serverId
,
qint64
sessionId
);
void
externalGameCommandContainerReceived
(
const
CommandContainer
&
cont
,
int
playerId
,
int
serverId
,
qint64
sessionId
);
void
externalGameEventContainerReceived
(
const
GameEventContainer
&
cont
,
qint64
sessionId
);
void
externalResponseReceived
(
const
Response
&
resp
,
qint64
sessionId
);
virtual
void
doSendIslMessage
(
const
IslMessage
&
msg
,
int
serverId
)
{
}
protected:
void
prepareDestroy
();
void
setDatabaseInterface
(
Server_DatabaseInterface
*
_databaseInterface
);
QList
<
Server_ProtocolHandler
*>
clients
;
QMap
<
qint64
,
Server_ProtocolHandler
*>
usersBySessionId
;
QMap
<
QString
,
Server_ProtocolHandler
*>
users
;
QMap
<
qint64
,
Server_AbstractUserInterface
*>
externalUsersBySessionId
;
QMap
<
QString
,
Server_AbstractUserInterface
*>
externalUsers
;
QMap
<
int
,
Server_Room
*>
rooms
;
QMap
<
QThread
*
,
Server_DatabaseInterface
*>
databaseInterfaces
;
int
getUsersCount
()
const
;
int
getGamesCount
()
const
;
void
addRoom
(
Server_Room
*
newRoom
);
void
prepareDestroy
();
void
setDatabaseInterface
(
Server_DatabaseInterface
*
_databaseInterface
);
QList
<
Server_ProtocolHandler
*>
clients
;
QMap
<
qint64
,
Server_ProtocolHandler
*>
usersBySessionId
;
QMap
<
QString
,
Server_ProtocolHandler
*>
users
;
QMap
<
qint64
,
Server_AbstractUserInterface
*>
externalUsersBySessionId
;
QMap
<
QString
,
Server_AbstractUserInterface
*>
externalUsers
;
QMap
<
int
,
Server_Room
*>
rooms
;
QMap
<
QThread
*
,
Server_DatabaseInterface
*>
databaseInterfaces
;
int
getUsersCount
()
const
;
int
getGamesCount
()
const
;
void
addRoom
(
Server_Room
*
newRoom
);
};
#endif
common/server_abstractuserinterface.cpp
View file @
4e8ba699
...
...
@@ -15,82 +15,82 @@
void
Server_AbstractUserInterface
::
sendProtocolItemByType
(
ServerMessage
::
MessageType
type
,
const
::
google
::
protobuf
::
Message
&
item
)
{
switch
(
type
)
{
case
ServerMessage
::
RESPONSE
:
sendProtocolItem
(
static_cast
<
const
Response
&>
(
item
));
break
;
case
ServerMessage
::
SESSION_EVENT
:
sendProtocolItem
(
static_cast
<
const
SessionEvent
&>
(
item
));
break
;
case
ServerMessage
::
GAME_EVENT_CONTAINER
:
sendProtocolItem
(
static_cast
<
const
GameEventContainer
&>
(
item
));
break
;
case
ServerMessage
::
ROOM_EVENT
:
sendProtocolItem
(
static_cast
<
const
RoomEvent
&>
(
item
));
break
;
}
switch
(
type
)
{
case
ServerMessage
::
RESPONSE
:
sendProtocolItem
(
static_cast
<
const
Response
&>
(
item
));
break
;
case
ServerMessage
::
SESSION_EVENT
:
sendProtocolItem
(
static_cast
<
const
SessionEvent
&>
(
item
));
break
;
case
ServerMessage
::
GAME_EVENT_CONTAINER
:
sendProtocolItem
(
static_cast
<
const
GameEventContainer
&>
(
item
));
break
;
case
ServerMessage
::
ROOM_EVENT
:
sendProtocolItem
(
static_cast
<
const
RoomEvent
&>
(
item
));
break
;
}
}
SessionEvent
*
Server_AbstractUserInterface
::
prepareSessionEvent
(
const
::
google
::
protobuf
::
Message
&
sessionEvent
)
{
SessionEvent
*
event
=
new
SessionEvent
;
event
->
GetReflection
()
->
MutableMessage
(
event
,
sessionEvent
.
GetDescriptor
()
->
FindExtensionByName
(
"ext"
))
->
CopyFrom
(
sessionEvent
);
return
event
;
SessionEvent
*
event
=
new
SessionEvent
;
event
->
GetReflection
()
->
MutableMessage
(
event
,
sessionEvent
.
GetDescriptor
()
->
FindExtensionByName
(
"ext"
))
->
CopyFrom
(
sessionEvent
);
return
event
;
}
void
Server_AbstractUserInterface
::
sendResponseContainer
(
const
ResponseContainer
&
responseContainer
,
Response
::
ResponseCode
responseCode
)
{
const
QList
<
QPair
<
ServerMessage
::
MessageType
,
::
google
::
protobuf
::
Message
*>
>
&
preResponseQueue
=
responseContainer
.
getPreResponseQueue
();
for
(
int
i
=
0
;
i
<
preResponseQueue
.
size
();
++
i
)
sendProtocolItemByType
(
preResponseQueue
[
i
].
first
,
*
preResponseQueue
[
i
].
second
);
if
(
responseCode
!=
Response
::
RespNothing
)
{
Response
response
;
response
.
set_cmd_id
(
responseContainer
.
getCmdId
());
response
.
set_response_code
(
responseCode
);
::
google
::
protobuf
::
Message
*
responseExtension
=
responseContainer
.
getResponseExtension
();
if
(
responseExtension
)
response
.
GetReflection
()
->
MutableMessage
(
&
response
,
responseExtension
->
GetDescriptor
()
->
FindExtensionByName
(
"ext"
))
->
CopyFrom
(
*
responseExtension
);
sendProtocolItem
(
response
);
}
const
QList
<
QPair
<
ServerMessage
::
MessageType
,
::
google
::
protobuf
::
Message
*>
>
&
postResponseQueue
=
responseContainer
.
getPostResponseQueue
();
for
(
int
i
=
0
;
i
<
postResponseQueue
.
size
();
++
i
)
sendProtocolItemByType
(
postResponseQueue
[
i
].
first
,
*
postResponseQueue
[
i
].
second
);
const
QList
<
QPair
<
ServerMessage
::
MessageType
,
::
google
::
protobuf
::
Message
*>
>
&
preResponseQueue
=
responseContainer
.
getPreResponseQueue
();
for
(
int
i
=
0
;
i
<
preResponseQueue
.
size
();
++
i
)
sendProtocolItemByType
(
preResponseQueue
[
i
].
first
,
*
preResponseQueue
[
i
].
second
);
if
(
responseCode
!=
Response
::
RespNothing
)
{
Response
response
;
response
.
set_cmd_id
(
responseContainer
.
getCmdId
());
response
.
set_response_code
(
responseCode
);
::
google
::
protobuf
::
Message
*
responseExtension
=
responseContainer
.
getResponseExtension
();
if
(
responseExtension
)
response
.
GetReflection
()
->
MutableMessage
(
&
response
,
responseExtension
->
GetDescriptor
()
->
FindExtensionByName
(
"ext"
))
->
CopyFrom
(
*
responseExtension
);
sendProtocolItem
(
response
);
}
const
QList
<
QPair
<
ServerMessage
::
MessageType
,
::
google
::
protobuf
::
Message
*>
>
&
postResponseQueue
=
responseContainer
.
getPostResponseQueue
();
for
(
int
i
=
0
;
i
<
postResponseQueue
.
size
();
++
i
)
sendProtocolItemByType
(
postResponseQueue
[
i
].
first
,
*
postResponseQueue
[
i
].
second
);
}
void
Server_AbstractUserInterface
::
playerRemovedFromGame
(
Server_Game
*
game
)
{
qDebug
()
<<
"Server_AbstractUserInterface::playerRemovedFromGame(): gameId ="
<<
game
->
getGameId
();
QMutexLocker
locker
(
&
gameListMutex
);
games
.
remove
(
game
->
getGameId
());
qDebug
()
<<
"Server_AbstractUserInterface::playerRemovedFromGame(): gameId ="
<<
game
->
getGameId
();
QMutexLocker
locker
(
&
gameListMutex
);
games
.
remove
(
game
->
getGameId
());
}
void
Server_AbstractUserInterface
::
playerAddedToGame
(
int
gameId
,
int
roomId
,
int
playerId
)
{
qDebug
()
<<
"Server_AbstractUserInterface::playerAddedToGame(): gameId ="
<<
gameId
;
QMutexLocker
locker
(
&
gameListMutex
);
games
.
insert
(
gameId
,
QPair
<
int
,
int
>
(
roomId
,
playerId
));
qDebug
()
<<
"Server_AbstractUserInterface::playerAddedToGame(): gameId ="
<<
gameId
;
QMutexLocker
locker
(
&
gameListMutex
);
games
.
insert
(
gameId
,
QPair
<
int
,
int
>
(
roomId
,
playerId
));
}
void
Server_AbstractUserInterface
::
joinPersistentGames
(
ResponseContainer
&
rc
)
{
QList
<
PlayerReference
>
gamesToJoin
=
server
->
getPersistentPlayerReferences
(
QString
::
fromStdString
(
userInfo
->
name
()));
server
->
roomsLock
.
lockForRead
();
for
(
int
i
=
0
;
i
<
gamesToJoin
.
size
();
++
i
)
{
const
PlayerReference
&
pr
=
gamesToJoin
.
at
(
i
);
Server_Room
*
room
=
server
->
getRooms
().
value
(
pr
.
getRoomId
());
if
(
!
room
)
continue
;
QReadLocker
roomGamesLocker
(
&
room
->
gamesLock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
pr
.
getGameId
());
if
(
!
game
)
continue
;
QMutexLocker
gameLocker
(
&
game
->
gameMutex
);
Server_Player
*
player
=
game
->
getPlayers
().
value
(
pr
.
getPlayerId
());
player
->
setUserInterface
(
this
);
playerAddedToGame
(
game
->
getGameId
(),
room
->
getId
(),
player
->
getPlayerId
());
game
->
createGameJoinedEvent
(
player
,
rc
,
true
);
}
server
->
roomsLock
.
unlock
();
QList
<
PlayerReference
>
gamesToJoin
=
server
->
getPersistentPlayerReferences
(
QString
::
fromStdString
(
userInfo
->
name
()));
server
->
roomsLock
.
lockForRead
();
for
(
int
i
=
0
;
i
<
gamesToJoin
.
size
();
++
i
)
{
const
PlayerReference
&
pr
=
gamesToJoin
.
at
(
i
);
Server_Room
*
room
=
server
->
getRooms
().
value
(
pr
.
getRoomId
());
if
(
!
room
)
continue
;
QReadLocker
roomGamesLocker
(
&
room
->
gamesLock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
pr
.
getGameId
());
if
(
!
game
)
continue
;
QMutexLocker
gameLocker
(
&
game
->
gameMutex
);
Server_Player
*
player
=
game
->
getPlayers
().
value
(
pr
.
getPlayerId
());
player
->
setUserInterface
(
this
);
playerAddedToGame
(
game
->
getGameId
(),
room
->
getId
(),
player
->
getPlayerId
());
game
->
createGameJoinedEvent
(
player
,
rc
,
true
);
}
server
->
roomsLock
.
unlock
();
}
common/server_abstractuserinterface.h
View file @
4e8ba699
...
...
@@ -18,31 +18,31 @@ class Server_Game;
class
Server_AbstractUserInterface
:
public
ServerInfo_User_Container
{
private:
mutable
QMutex
gameListMutex
;
QMap
<
int
,
QPair
<
int
,
int
>
>
games
;
// gameId -> (roomId, playerId)
mutable
QMutex
gameListMutex
;
QMap
<
int
,
QPair
<
int
,
int
>
>
games
;
// gameId -> (roomId, playerId)
protected:
Server
*
server
;
Server
*
server
;
public:
Server_AbstractUserInterface
(
Server
*
_server
)
:
server
(
_server
)
{
}
Server_AbstractUserInterface
(
Server
*
_server
,
const
ServerInfo_User_Container
&
other
)
:
ServerInfo_User_Container
(
other
),
server
(
_server
)
{
}
virtual
~
Server_AbstractUserInterface
()
{
}
virtual
int
getLastCommandTime
()
const
=
0
;
void
playerRemovedFromGame
(
Server_Game
*
game
);
void
playerAddedToGame
(
int
gameId
,
int
roomId
,
int
playerId
);
void
joinPersistentGames
(
ResponseContainer
&
rc
);
QMap
<
int
,
QPair
<
int
,
int
>
>
getGames
()
const
{
QMutexLocker
locker
(
&
gameListMutex
);
return
games
;
}
virtual
void
sendProtocolItem
(
const
Response
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
SessionEvent
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
GameEventContainer
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
RoomEvent
&
item
)
=
0
;
void
sendProtocolItemByType
(
ServerMessage
::
MessageType
type
,
const
::
google
::
protobuf
::
Message
&
item
);
static
SessionEvent
*
prepareSessionEvent
(
const
::
google
::
protobuf
::
Message
&
sessionEvent
);
void
sendResponseContainer
(
const
ResponseContainer
&
responseContainer
,
Response
::
ResponseCode
responseCode
);
Server_AbstractUserInterface
(
Server
*
_server
)
:
server
(
_server
)
{
}
Server_AbstractUserInterface
(
Server
*
_server
,
const
ServerInfo_User_Container
&
other
)
:
ServerInfo_User_Container
(
other
),
server
(
_server
)
{
}
virtual
~
Server_AbstractUserInterface
()
{
}
virtual
int
getLastCommandTime
()
const
=
0
;
void
playerRemovedFromGame
(
Server_Game
*
game
);
void
playerAddedToGame
(
int
gameId
,
int
roomId
,
int
playerId
);
void
joinPersistentGames
(
ResponseContainer
&
rc
);
QMap
<
int
,
QPair
<
int
,
int
>
>
getGames
()
const
{
QMutexLocker
locker
(
&
gameListMutex
);
return
games
;
}
virtual
void
sendProtocolItem
(
const
Response
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
SessionEvent
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
GameEventContainer
&
item
)
=
0
;
virtual
void
sendProtocolItem
(
const
RoomEvent
&
item
)
=
0
;
void
sendProtocolItemByType
(
ServerMessage
::
MessageType
type
,
const
::
google
::
protobuf
::
Message
&
item
);
static
SessionEvent
*
prepareSessionEvent
(
const
::
google
::
protobuf
::
Message
&
sessionEvent
);
void
sendResponseContainer
(
const
ResponseContainer
&
responseContainer
,
Response
::
ResponseCode
responseCode
);
};
#endif
common/server_arrow.cpp
View file @
4e8ba699
...
...
@@ -14,17 +14,17 @@ Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget
void
Server_Arrow
::
getInfo
(
ServerInfo_Arrow
*
info
)
{
info
->
set_id
(
id
);
info
->
set_start_player_id
(
startCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_start_zone
(
startCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_start_card_id
(
startCard
->
getId
());
info
->
mutable_arrow_color
()
->
CopyFrom
(
arrowColor
);
info
->
set_id
(
id
);
info
->
set_start_player_id
(
startCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_start_zone
(
startCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_start_card_id
(
startCard
->
getId
());
info
->
mutable_arrow_color
()
->
CopyFrom
(
arrowColor
);
Server_Card
*
targetCard
=
qobject_cast
<
Server_Card
*>
(
targetItem
);
if
(
targetCard
)
{
info
->
set_target_player_id
(
targetCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_target_zone
(
targetCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_target_card_id
(
targetCard
->
getId
());
}
else
info
->
set_target_player_id
(
static_cast
<
Server_Player
*>
(
targetItem
)
->
getPlayerId
());
Server_Card
*
targetCard
=
qobject_cast
<
Server_Card
*>
(
targetItem
);
if
(
targetCard
)
{
info
->
set_target_player_id
(
targetCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_target_zone
(
targetCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_target_card_id
(
targetCard
->
getId
());
}
else
info
->
set_target_player_id
(
static_cast
<
Server_Player
*>
(
targetItem
)
->
getPlayerId
());
}
common/server_arrow.h
View file @
4e8ba699
...
...
@@ -9,18 +9,18 @@ class ServerInfo_Arrow;
class
Server_Arrow
{
private:
int
id
;
Server_Card
*
startCard
;
Server_ArrowTarget
*
targetItem
;
color
arrowColor
;
int
id
;
Server_Card
*
startCard
;
Server_ArrowTarget
*
targetItem
;
color
arrowColor
;
public:
Server_Arrow
(
int
_id
,
Server_Card
*
_startCard
,
Server_ArrowTarget
*
_targetItem
,
const
color
&
_arrowColor
);
int
getId
()
const
{
return
id
;
}
Server_Card
*
getStartCard
()
const
{
return
startCard
;
}
Server_ArrowTarget
*
getTargetItem
()
const
{
return
targetItem
;
}
const
color
&
getColor
()
const
{
return
arrowColor
;
}
void
getInfo
(
ServerInfo_Arrow
*
info
);
Server_Arrow
(
int
_id
,
Server_Card
*
_startCard
,
Server_ArrowTarget
*
_targetItem
,
const
color
&
_arrowColor
);
int
getId
()
const
{
return
id
;
}
Server_Card
*
getStartCard
()
const
{
return
startCard
;
}
Server_ArrowTarget
*
getTargetItem
()
const
{
return
targetItem
;
}
const
color
&
getColor
()
const
{
return
arrowColor
;
}
void
getInfo
(
ServerInfo_Arrow
*
info
);
};
#endif
common/server_arrowtarget.cpp
View file @
4e8ba699
#include
"server_arrowtarget.h"
\ No newline at end of file
#include
"server_arrowtarget.h"
common/server_arrowtarget.h
View file @
4e8ba699
...
...
@@ -4,7 +4,7 @@
#include
<QObject>
class
Server_ArrowTarget
:
public
QObject
{
Q_OBJECT
Q_OBJECT
};
#endif
common/server_card.cpp
View file @
4e8ba699
...
...
@@ -23,138 +23,138 @@
#include
"pb/serverinfo_card.pb.h"
Server_Card
::
Server_Card
(
QString
_name
,
int
_id
,
int
_coord_x
,
int
_coord_y
,
Server_CardZone
*
_zone
)
:
zone
(
_zone
),
id
(
_id
),
coord_x
(
_coord_x
),
coord_y
(
_coord_y
),
name
(
_name
),
tapped
(
false
),
attacking
(
false
),
facedown
(
false
),
color
(
QString
()),
power
(
-
1
),
toughness
(
-
1
),
annotation
(
QString
()),
destroyOnZoneChange
(
false
),
doesntUntap
(
false
),
parentCard
(
0
)
:
zone
(
_zone
),
id
(
_id
),
coord_x
(
_coord_x
),
coord_y
(
_coord_y
),
name
(
_name
),
tapped
(
false
),
attacking
(
false
),
facedown
(
false
),
color
(
QString
()),
power
(
-
1
),
toughness
(
-
1
),
annotation
(
QString
()),
destroyOnZoneChange
(
false
),
doesntUntap
(
false
),
parentCard
(
0
)
{
}
Server_Card
::~
Server_Card
()
{
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
while
(
!
attachedCards
.
isEmpty
())
attachedCards
.
first
()
->
setParentCard
(
0
);
if
(
parentCard
)
parentCard
->
removeAttachedCard
(
this
);
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
while
(
!
attachedCards
.
isEmpty
())
attachedCards
.
first
()
->
setParentCard
(
0
);
if
(
parentCard
)
parentCard
->
removeAttachedCard
(
this
);
}
void
Server_Card
::
resetState
()
{
counters
.
clear
();
setTapped
(
false
);
setAttacking
(
false
);
power
=
-
1
;
toughness
=
-
1
;
setAnnotation
(
QString
());
setDoesntUntap
(
false
);
counters
.
clear
();
setTapped
(
false
);
setAttacking
(
false
);
power
=
-
1
;
toughness
=
-
1
;
setAnnotation
(
QString
());
setDoesntUntap
(
false
);
}
QString
Server_Card
::
setAttribute
(
CardAttribute
attribute
,
const
QString
&
avalue
,
bool
allCards
)
{
switch
(
attribute
)
{
case
AttrTapped
:
{
bool
value
=
avalue
==
"1"
;
if
(
!
(
!
value
&&
allCards
&&
doesntUntap
))
setTapped
(
value
);
break
;
}
case
AttrAttacking
:
setAttacking
(
avalue
==
"1"
);
break
;
case
AttrFaceDown
:
setFaceDown
(
avalue
==
"1"
);
break
;
case
AttrColor
:
setColor
(
avalue
);
break
;
case
AttrPT
:
setPT
(
avalue
);
return
getPT
();
case
AttrAnnotation
:
setAnnotation
(
avalue
);
break
;
case
AttrDoesntUntap
:
setDoesntUntap
(
avalue
==
"1"
);
break
;
}
return
avalue
;
switch
(
attribute
)
{
case
AttrTapped
:
{
bool
value
=
avalue
==
"1"
;
if
(
!
(
!
value
&&
allCards
&&
doesntUntap
))
setTapped
(
value
);
break
;
}
case
AttrAttacking
:
setAttacking
(
avalue
==
"1"
);
break
;
case
AttrFaceDown
:
setFaceDown
(
avalue
==
"1"
);
break
;
case
AttrColor
:
setColor
(
avalue
);
break
;
case
AttrPT
:
setPT
(
avalue
);
return
getPT
();
case
AttrAnnotation
:
setAnnotation
(
avalue
);
break
;
case
AttrDoesntUntap
:
setDoesntUntap
(
avalue
==
"1"
);
break
;
}
return
avalue
;
}
void
Server_Card
::
setCounter
(
int
id
,
int
value
)
{
if
(
value
)
counters
.
insert
(
id
,
value
);
else
counters
.
remove
(
id
);
if
(
value
)
counters
.
insert
(
id
,
value
);
else
counters
.
remove
(
id
);
}
void
Server_Card
::
setPT
(
const
QString
&
_pt
)
{
if
(
_pt
.
isEmpty
())
{
power
=
0
;
toughness
=
-
1
;
}
else
{
int
sep
=
_pt
.
indexOf
(
'/'
);
QString
p1
=
_pt
.
left
(
sep
);
QString
p2
=
_pt
.
mid
(
sep
+
1
);
if
(
p1
.
isEmpty
()
||
p2
.
isEmpty
())
return
;
if
((
p1
[
0
]
==
'+'
)
||
(
p2
[
0
]
==
'+'
))
{
if
(
power
<
0
)
power
=
0
;
if
(
toughness
<
0
)
toughness
=
0
;
}
if
(
p1
[
0
]
==
'+'
)
power
+=
p1
.
mid
(
1
).
toInt
();
else
power
=
p1
.
toInt
();
if
(
p2
[
0
]
==
'+'
)
toughness
+=
p2
.
mid
(
1
).
toInt
();
else
toughness
=
p2
.
toInt
();
}
if
(
_pt
.
isEmpty
())
{
power
=
0
;
toughness
=
-
1
;
}
else
{
int
sep
=
_pt
.
indexOf
(
'/'
);
QString
p1
=
_pt
.
left
(
sep
);
QString
p2
=
_pt
.
mid
(
sep
+
1
);
if
(
p1
.
isEmpty
()
||
p2
.
isEmpty
())
return
;
if
((
p1
[
0
]
==
'+'
)
||
(
p2
[
0
]
==
'+'
))
{
if
(
power
<
0
)
power
=
0
;
if
(
toughness
<
0
)
toughness
=
0
;
}
if
(
p1
[
0
]
==
'+'
)
power
+=
p1
.
mid
(
1
).
toInt
();
else
power
=
p1
.
toInt
();
if
(
p2
[
0
]
==
'+'
)
toughness
+=
p2
.
mid
(
1
).
toInt
();
else
toughness
=
p2
.
toInt
();
}
}
QString
Server_Card
::
getPT
()
const
{
if
(
toughness
<
0
)
return
QString
(
""
);
return
QString
::
number
(
power
)
+
"/"
+
QString
::
number
(
toughness
);
if
(
toughness
<
0
)
return
QString
(
""
);
return
QString
::
number
(
power
)
+
"/"
+
QString
::
number
(
toughness
);
}
void
Server_Card
::
setParentCard
(
Server_Card
*
_parentCard
)
{
if
(
parentCard
)
parentCard
->
removeAttachedCard
(
this
);
parentCard
=
_parentCard
;
if
(
parentCard
)
parentCard
->
addAttachedCard
(
this
);
if
(
parentCard
)
parentCard
->
removeAttachedCard
(
this
);
parentCard
=
_parentCard
;
if
(
parentCard
)
parentCard
->
addAttachedCard
(
this
);
}
void
Server_Card
::
getInfo
(
ServerInfo_Card
*
info
)
{
QString
displayedName
=
facedown
?
QString
()
:
name
;
info
->
set_id
(
id
);
info
->
set_name
(
displayedName
.
toStdString
());
info
->
set_x
(
coord_x
);
info
->
set_y
(
coord_y
);
if
(
facedown
)
info
->
set_face_down
(
true
);
info
->
set_tapped
(
tapped
);
if
(
attacking
)
info
->
set_attacking
(
true
);
if
(
!
color
.
isEmpty
())
info
->
set_color
(
color
.
toStdString
());
const
QString
ptStr
=
getPT
();
if
(
!
ptStr
.
isEmpty
())
info
->
set_pt
(
ptStr
.
toStdString
());
if
(
!
annotation
.
isEmpty
())
info
->
set_annotation
(
annotation
.
toStdString
());
if
(
destroyOnZoneChange
)
info
->
set_destroy_on_zone_change
(
true
);
if
(
doesntUntap
)
info
->
set_doesnt_untap
(
true
);
QMapIterator
<
int
,
int
>
cardCounterIterator
(
counters
);
while
(
cardCounterIterator
.
hasNext
())
{
cardCounterIterator
.
next
();
ServerInfo_CardCounter
*
counterInfo
=
info
->
add_counter_list
();
counterInfo
->
set_id
(
cardCounterIterator
.
key
());
counterInfo
->
set_value
(
cardCounterIterator
.
value
());
}
QString
displayedName
=
facedown
?
QString
()
:
name
;
info
->
set_id
(
id
);
info
->
set_name
(
displayedName
.
toStdString
());
info
->
set_x
(
coord_x
);
info
->
set_y
(
coord_y
);
if
(
facedown
)
info
->
set_face_down
(
true
);
info
->
set_tapped
(
tapped
);
if
(
attacking
)
info
->
set_attacking
(
true
);
if
(
!
color
.
isEmpty
())
info
->
set_color
(
color
.
toStdString
());
const
QString
ptStr
=
getPT
();
if
(
!
ptStr
.
isEmpty
())
info
->
set_pt
(
ptStr
.
toStdString
());
if
(
!
annotation
.
isEmpty
())
info
->
set_annotation
(
annotation
.
toStdString
());
if
(
destroyOnZoneChange
)
info
->
set_destroy_on_zone_change
(
true
);
if
(
doesntUntap
)
info
->
set_doesnt_untap
(
true
);
QMapIterator
<
int
,
int
>
cardCounterIterator
(
counters
);
while
(
cardCounterIterator
.
hasNext
())
{
cardCounterIterator
.
next
();
ServerInfo_CardCounter
*
counterInfo
=
info
->
add_counter_list
();
counterInfo
->
set_id
(
cardCounterIterator
.
key
());
counterInfo
->
set_value
(
cardCounterIterator
.
value
());
}
if
(
parentCard
)
{
info
->
set_attach_player_id
(
parentCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_attach_zone
(
parentCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_attach_card_id
(
parentCard
->
getId
());
}
if
(
parentCard
)
{
info
->
set_attach_player_id
(
parentCard
->
getZone
()
->
getPlayer
()
->
getPlayerId
());
info
->
set_attach_zone
(
parentCard
->
getZone
()
->
getName
().
toStdString
());
info
->
set_attach_card_id
(
parentCard
->
getId
());
}
}
common/server_card.h
View file @
4e8ba699
...
...
@@ -29,68 +29,68 @@ class Server_CardZone;
class
ServerInfo_Card
;
class
Server_Card
:
public
Server_ArrowTarget
{
Q_OBJECT
Q_OBJECT
private:
Server_CardZone
*
zone
;
int
id
;
int
coord_x
,
coord_y
;
QString
name
;
QMap
<
int
,
int
>
counters
;
bool
tapped
;
bool
attacking
;
bool
facedown
;
QString
color
;
int
power
,
toughness
;
QString
annotation
;
bool
destroyOnZoneChange
;
bool
doesntUntap
;
Server_Card
*
parentCard
;
QList
<
Server_Card
*>
attachedCards
;
Server_CardZone
*
zone
;
int
id
;
int
coord_x
,
coord_y
;
QString
name
;
QMap
<
int
,
int
>
counters
;
bool
tapped
;
bool
attacking
;
bool
facedown
;
QString
color
;
int
power
,
toughness
;
QString
annotation
;
bool
destroyOnZoneChange
;
bool
doesntUntap
;
Server_Card
*
parentCard
;
QList
<
Server_Card
*>
attachedCards
;
public:
Server_Card
(
QString
_name
,
int
_id
,
int
_coord_x
,
int
_coord_y
,
Server_CardZone
*
_zone
=
0
);
~
Server_Card
();
Server_CardZone
*
getZone
()
const
{
return
zone
;
}
void
setZone
(
Server_CardZone
*
_zone
)
{
zone
=
_zone
;
}
int
getId
()
const
{
return
id
;
}
int
getX
()
const
{
return
coord_x
;
}
int
getY
()
const
{
return
coord_y
;
}
QString
getName
()
const
{
return
name
;
}
const
QMap
<
int
,
int
>
&
getCounters
()
const
{
return
counters
;
}
int
getCounter
(
int
id
)
const
{
return
counters
.
value
(
id
,
0
);
}
bool
getTapped
()
const
{
return
tapped
;
}
bool
getAttacking
()
const
{
return
attacking
;
}
bool
getFaceDown
()
const
{
return
facedown
;
}
QString
getColor
()
const
{
return
color
;
}
QString
getPT
()
const
;
QString
getAnnotation
()
const
{
return
annotation
;
}
bool
getDoesntUntap
()
const
{
return
doesntUntap
;
}
bool
getDestroyOnZoneChange
()
const
{
return
destroyOnZoneChange
;
}
Server_Card
*
getParentCard
()
const
{
return
parentCard
;
}
const
QList
<
Server_Card
*>
&
getAttachedCards
()
const
{
return
attachedCards
;
}
Server_Card
(
QString
_name
,
int
_id
,
int
_coord_x
,
int
_coord_y
,
Server_CardZone
*
_zone
=
0
);
~
Server_Card
();
Server_CardZone
*
getZone
()
const
{
return
zone
;
}
void
setZone
(
Server_CardZone
*
_zone
)
{
zone
=
_zone
;
}
int
getId
()
const
{
return
id
;
}
int
getX
()
const
{
return
coord_x
;
}
int
getY
()
const
{
return
coord_y
;
}
QString
getName
()
const
{
return
name
;
}
const
QMap
<
int
,
int
>
&
getCounters
()
const
{
return
counters
;
}
int
getCounter
(
int
id
)
const
{
return
counters
.
value
(
id
,
0
);
}
bool
getTapped
()
const
{
return
tapped
;
}
bool
getAttacking
()
const
{
return
attacking
;
}
bool
getFaceDown
()
const
{
return
facedown
;
}
QString
getColor
()
const
{
return
color
;
}
QString
getPT
()
const
;
QString
getAnnotation
()
const
{
return
annotation
;
}
bool
getDoesntUntap
()
const
{
return
doesntUntap
;
}
bool
getDestroyOnZoneChange
()
const
{
return
destroyOnZoneChange
;
}
Server_Card
*
getParentCard
()
const
{
return
parentCard
;
}
const
QList
<
Server_Card
*>
&
getAttachedCards
()
const
{
return
attachedCards
;
}
void
setId
(
int
_id
)
{
id
=
_id
;
}
void
setCoords
(
int
x
,
int
y
)
{
coord_x
=
x
;
coord_y
=
y
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
void
setCounter
(
int
id
,
int
value
);
void
setTapped
(
bool
_tapped
)
{
tapped
=
_tapped
;
}
void
setAttacking
(
bool
_attacking
)
{
attacking
=
_attacking
;
}
void
setFaceDown
(
bool
_facedown
)
{
facedown
=
_facedown
;
}
void
setColor
(
const
QString
&
_color
)
{
color
=
_color
;
}
void
setPT
(
const
QString
&
_pt
);
void
setAnnotation
(
const
QString
&
_annotation
)
{
annotation
=
_annotation
;
}
void
setDestroyOnZoneChange
(
bool
_destroy
)
{
destroyOnZoneChange
=
_destroy
;
}
void
setDoesntUntap
(
bool
_doesntUntap
)
{
doesntUntap
=
_doesntUntap
;
}
void
setParentCard
(
Server_Card
*
_parentCard
);
void
addAttachedCard
(
Server_Card
*
card
)
{
attachedCards
.
append
(
card
);
}
void
removeAttachedCard
(
Server_Card
*
card
)
{
attachedCards
.
removeAt
(
attachedCards
.
indexOf
(
card
));
}
void
resetState
();
QString
setAttribute
(
CardAttribute
attribute
,
const
QString
&
avalue
,
bool
allCards
);
void
getInfo
(
ServerInfo_Card
*
info
);
void
setId
(
int
_id
)
{
id
=
_id
;
}
void
setCoords
(
int
x
,
int
y
)
{
coord_x
=
x
;
coord_y
=
y
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
void
setCounter
(
int
id
,
int
value
);
void
setTapped
(
bool
_tapped
)
{
tapped
=
_tapped
;
}
void
setAttacking
(
bool
_attacking
)
{
attacking
=
_attacking
;
}
void
setFaceDown
(
bool
_facedown
)
{
facedown
=
_facedown
;
}
void
setColor
(
const
QString
&
_color
)
{
color
=
_color
;
}
void
setPT
(
const
QString
&
_pt
);
void
setAnnotation
(
const
QString
&
_annotation
)
{
annotation
=
_annotation
;
}
void
setDestroyOnZoneChange
(
bool
_destroy
)
{
destroyOnZoneChange
=
_destroy
;
}
void
setDoesntUntap
(
bool
_doesntUntap
)
{
doesntUntap
=
_doesntUntap
;
}
void
setParentCard
(
Server_Card
*
_parentCard
);
void
addAttachedCard
(
Server_Card
*
card
)
{
attachedCards
.
append
(
card
);
}
void
removeAttachedCard
(
Server_Card
*
card
)
{
attachedCards
.
removeAt
(
attachedCards
.
indexOf
(
card
));
}
void
resetState
();
QString
setAttribute
(
CardAttribute
attribute
,
const
QString
&
avalue
,
bool
allCards
);
void
getInfo
(
ServerInfo_Card
*
info
);
};
#endif
common/server_cardzone.h
View file @
4e8ba699
...
...
@@ -33,48 +33,48 @@ class GameEventStorage;
class
Server_CardZone
{
private:
Server_Player
*
player
;
QString
name
;
bool
has_coords
;
ServerInfo_Zone
::
ZoneType
type
;
int
cardsBeingLookedAt
;
QSet
<
int
>
playersWithWritePermission
;
bool
alwaysRevealTopCard
;
QList
<
Server_Card
*>
cards
;
QMap
<
int
,
QMap
<
int
,
Server_Card
*>
>
coordinateMap
;
// y -> (x -> card)
QMap
<
int
,
QMultiMap
<
QString
,
int
>
>
freePilesMap
;
// y -> (cardName -> x)
QMap
<
int
,
int
>
freeSpaceMap
;
// y -> x
void
removeCardFromCoordMap
(
Server_Card
*
card
,
int
oldX
,
int
oldY
);
void
insertCardIntoCoordMap
(
Server_Card
*
card
,
int
x
,
int
y
);
Server_Player
*
player
;
QString
name
;
bool
has_coords
;
ServerInfo_Zone
::
ZoneType
type
;
int
cardsBeingLookedAt
;
QSet
<
int
>
playersWithWritePermission
;
bool
alwaysRevealTopCard
;
QList
<
Server_Card
*>
cards
;
QMap
<
int
,
QMap
<
int
,
Server_Card
*>
>
coordinateMap
;
// y -> (x -> card)
QMap
<
int
,
QMultiMap
<
QString
,
int
>
>
freePilesMap
;
// y -> (cardName -> x)
QMap
<
int
,
int
>
freeSpaceMap
;
// y -> x
void
removeCardFromCoordMap
(
Server_Card
*
card
,
int
oldX
,
int
oldY
);
void
insertCardIntoCoordMap
(
Server_Card
*
card
,
int
x
,
int
y
);
public:
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ServerInfo_Zone
::
ZoneType
_type
);
~
Server_CardZone
();
const
QList
<
Server_Card
*>
&
getCards
()
const
{
return
cards
;
}
int
removeCard
(
Server_Card
*
card
);
Server_Card
*
getCard
(
int
id
,
int
*
position
=
NULL
,
bool
remove
=
false
);
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ServerInfo_Zone
::
ZoneType
_type
);
~
Server_CardZone
();
const
QList
<
Server_Card
*>
&
getCards
()
const
{
return
cards
;
}
int
removeCard
(
Server_Card
*
card
);
Server_Card
*
getCard
(
int
id
,
int
*
position
=
NULL
,
bool
remove
=
false
);
int
getCardsBeingLookedAt
()
const
{
return
cardsBeingLookedAt
;
}
void
setCardsBeingLookedAt
(
int
_cardsBeingLookedAt
)
{
cardsBeingLookedAt
=
_cardsBeingLookedAt
;
}
bool
hasCoords
()
const
{
return
has_coords
;
}
ServerInfo_Zone
::
ZoneType
getType
()
const
{
return
type
;
}
QString
getName
()
const
{
return
name
;
}
Server_Player
*
getPlayer
()
const
{
return
player
;
}
void
getInfo
(
ServerInfo_Zone
*
info
,
Server_Player
*
playerWhosAsking
,
bool
omniscient
);
int
getFreeGridColumn
(
int
x
,
int
y
,
const
QString
&
cardName
)
const
;
bool
isColumnEmpty
(
int
x
,
int
y
)
const
;
bool
isColumnStacked
(
int
x
,
int
y
)
const
;
void
fixFreeSpaces
(
GameEventStorage
&
ges
);
void
moveCardInRow
(
GameEventStorage
&
ges
,
Server_Card
*
card
,
int
x
,
int
y
);
void
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
);
void
updateCardCoordinates
(
Server_Card
*
card
,
int
oldX
,
int
oldY
);
void
shuffle
();
void
clear
();
void
addWritePermission
(
int
playerId
);
const
QSet
<
int
>
&
getPlayersWithWritePermission
()
const
{
return
playersWithWritePermission
;
}
bool
getAlwaysRevealTopCard
()
const
{
return
alwaysRevealTopCard
;
}
void
setAlwaysRevealTopCard
(
bool
_alwaysRevealTopCard
)
{
alwaysRevealTopCard
=
_alwaysRevealTopCard
;
}
int
getCardsBeingLookedAt
()
const
{
return
cardsBeingLookedAt
;
}
void
setCardsBeingLookedAt
(
int
_cardsBeingLookedAt
)
{
cardsBeingLookedAt
=
_cardsBeingLookedAt
;
}
bool
hasCoords
()
const
{
return
has_coords
;
}
ServerInfo_Zone
::
ZoneType
getType
()
const
{
return
type
;
}
QString
getName
()
const
{
return
name
;
}
Server_Player
*
getPlayer
()
const
{
return
player
;
}
void
getInfo
(
ServerInfo_Zone
*
info
,
Server_Player
*
playerWhosAsking
,
bool
omniscient
);
int
getFreeGridColumn
(
int
x
,
int
y
,
const
QString
&
cardName
)
const
;
bool
isColumnEmpty
(
int
x
,
int
y
)
const
;
bool
isColumnStacked
(
int
x
,
int
y
)
const
;
void
fixFreeSpaces
(
GameEventStorage
&
ges
);
void
moveCardInRow
(
GameEventStorage
&
ges
,
Server_Card
*
card
,
int
x
,
int
y
);
void
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
);
void
updateCardCoordinates
(
Server_Card
*
card
,
int
oldX
,
int
oldY
);
void
shuffle
();
void
clear
();
void
addWritePermission
(
int
playerId
);
const
QSet
<
int
>
&
getPlayersWithWritePermission
()
const
{
return
playersWithWritePermission
;
}
bool
getAlwaysRevealTopCard
()
const
{
return
alwaysRevealTopCard
;
}
void
setAlwaysRevealTopCard
(
bool
_alwaysRevealTopCard
)
{
alwaysRevealTopCard
=
_alwaysRevealTopCard
;
}
};
#endif
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment