Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
1cf4d1c8
Commit
1cf4d1c8
authored
Jan 09, 2009
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the new pack system now actually works (yay!)
parent
41b7ae72
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
353 additions
and
446 deletions
+353
-446
src/data/pack.cpp
src/data/pack.cpp
+237
-331
src/data/pack.hpp
src/data/pack.hpp
+63
-86
src/gui/set/random_pack_panel.cpp
src/gui/set/random_pack_panel.cpp
+49
-28
src/gui/set/random_pack_panel.hpp
src/gui/set/random_pack_panel.hpp
+4
-1
No files found.
src/data/pack.cpp
View file @
1cf4d1c8
This diff is collapsed.
Click to expand it.
src/data/pack.hpp
View file @
1cf4d1c8
...
...
@@ -14,7 +14,7 @@
#include <script/scriptable.hpp>
#include <boost/random/mersenne_twister.hpp>
#define USE_NEW_PACK_SYSTEM
0
#define USE_NEW_PACK_SYSTEM
1
#if !USE_NEW_PACK_SYSTEM
// =================================================================================================== OLD
...
...
@@ -103,20 +103,29 @@ class PackItemCache {
};
#else
// =================================================================================================== NEW
DECLARE_POINTER_TYPE
(
PackType
);
DECLARE_POINTER_TYPE
(
PackItem
);
DECLARE_POINTER_TYPE
(
PackInstance
);
DECLARE_POINTER_TYPE
(
Card
);
class
Set
;
DECLARE_POINTER_TYPE
(
Set
);
class
PackGenerator
;
// ----------------------------------------------------------------------------- : PackType
enum
OneMany
{
SELECT_ONE_OR_EMPTY
,
SELECT_ONE
,
SELECT_FIRST
enum
PackSelectType
{
SELECT_AUTO
,
SELECT_ALL
,
SELECT_REPLACE
,
SELECT_NO_REPLACE
,
SELECT_CYCLIC
,
SELECT_PROPORTIONAL
,
SELECT_NONEMPTY
,
SELECT_FIRST
};
/// A card pack description for playtesting
...
...
@@ -128,8 +137,7 @@ class PackType : public IntrusivePtrBase<PackType> {
Scriptable
<
bool
>
enabled
;
///< Is this pack enabled?
bool
selectable
;
///< Is this pack listed in the UI?
bool
summary
;
///< Should the total be listed for this type?
OneMany
select
;
///< Select one or many?
OptionalScript
cards
;
///< Script to select this type of cards (there are no items)
PackSelectType
select
;
///< What cards/items to select
OptionalScript
filter
;
///< Filter to select this type of cards
vector
<
PackItemP
>
items
;
///< Subpacks in this pack
...
...
@@ -140,24 +148,14 @@ class PackType : public IntrusivePtrBase<PackType> {
DECLARE_REFLECTION
();
};
// ----------------------------------------------------------------------------- : PackItem
enum
PackSelectType
{
PACK_REF_INHERIT
,
PACK_REF_REPLACE
,
PACK_REF_NO_REPLACE
,
PACK_REF_CYCLIC
};
/// An item in a PackType
class
PackItem
:
public
IntrusivePtrBase
<
PackItem
>
{
public:
PackItem
();
String
pack
;
///< Name of the pack to select cards from
String
name
;
///< Name of the pack to select cards from
Scriptable
<
int
>
amount
;
///< Number of cards of this type
Scriptable
<
double
>
weight
;
///< Relative probability of picking this item
PackSelectType
type
;
Scriptable
<
double
>
probability
;
///< Relative probability of picking this item
/// Update scripts, returns true if there is a change
bool
update
(
Context
&
ctx
);
...
...
@@ -166,86 +164,65 @@ class PackItem : public IntrusivePtrBase<PackItem> {
DECLARE_REFLECTION
();
};
// ----------------------------------------------------------------------------- : Generating / counting
// ---------------------------------------------------
: PackItemCache
// ---------------------------------------------------
-------------------------- : Generating / counting
class
PackItemCache
{
// A PackType that is instantiated for a particular Set,
// i.e. we now know the actual cards
class
PackInstance
:
public
IntrusivePtrBase
<
PackInstance
>
{
public:
PackI
temCache
(
Set
&
set
)
:
set
(
set
)
{}
PackI
nstance
(
const
PackType
&
pack_type
,
PackGenerator
&
parent
);
/// Look up a pack type by name
const
PackType
&
pack
(
const
String
&
name
);
/// Expect to pick this many copies from this pack, updates expected_copies
void
expect_copy
(
double
copies
=
1
);
/// Request some copies of this pack
void
request_copy
(
size_t
copies
=
1
);
protected:
Set
&
set
;
/// Generate cards if depth == at_depth
/** Some cards are (optionally) added to out and card_copies
* And also the copies of referenced items might be incremented
*
* Resets the count of this instance to 0 */
void
generate
(
vector
<
CardP
>*
out
);
/// The cards for a given PackItem
ScriptValueP
cardsFor
(
const
ScriptValueP
&
cards_script
);
inline
int
get_depth
()
const
{
return
depth
;
}
inline
bool
has_cards
()
const
{
return
!
cards
.
empty
();
}
inline
size_t
get_card_copies
()
const
{
return
card_copies
;
}
inline
double
get_expected_copies
()
const
{
return
expected_copies
;
}
private:
/// Lookup PackTypes by name
//%%
/// Cards for each PackType
map
<
ScriptValueP
,
ScriptValueP
>
item_cards
;
const
PackType
&
pack_type
;
PackGenerator
&
parent
;
int
depth
;
//< 0 = no items, otherwise 1+max depth of items refered to
vector
<
CardP
>
cards
;
//< All cards that pass the filter
size_t
count
;
//< Total number of non-empty cards/items
double
total_probability
;
//< Sum of item and card probabilities
size_t
requested_copies
;
//< The requested number of copies of this pack
size_t
card_copies
;
//< The number of cards that were chosen to come from this pack
double
expected_copies
;
};
// --------------------------------------------------- : Counting expected cards
/// Class for determining the *expected* number of cards from each type
class
PackItemCounter
:
PackItemCache
{
class
PackGenerator
{
public:
PackItemCounter
(
Set
&
set
,
map
<
const
PackType
*
,
double
>&
counts
)
:
PackItemCache
(
set
),
counts
(
counts
)
{}
/// Reset the generator, possibly switching the set or reseeding
void
reset
(
const
SetP
&
set
,
int
seed
);
///
Add a number of copies of the PackType to the counts, recurse into child items
void
addCountRecursive
(
const
PackType
&
pack
,
double
copies
);
void
addCountRecursive
(
const
PackItem
&
item
,
double
copies
);
///
Find the PackInstance for the PackType with the given name
PackInstance
&
get
(
const
String
&
name
);
PackInstance
&
get
(
const
PackTypeP
&
type
);
/// The probability that the given pack is non-empty
double
probabilityNonEmpty
(
const
PackType
&
pack
);
double
probabilityNonEmpty
(
const
PackItem
&
item
);
/// The counts will be stored here
map
<
const
PackType
*
,
double
>&
counts
;
/// Generate all cards, resets copies
void
generate
(
vector
<
CardP
>&
out
);
/// Update all card_copies counters, resets copies
void
update_card_counts
();
// only for PackInstance
SetP
set
;
///< The set
boost
::
mt19937
gen
;
///< Random generator
private:
/// The probability that a pack type is empty (cache)
//%map<const PackItem*,double> probability_empty;
};
// --------------------------------------------------- : PackItemCounter
/// Class for generating card packs
class
PackItemGenerator
:
PackItemCache
{
public:
PackItemGenerator
(
Set
&
set
,
vector
<
CardP
>&
cards
,
boost
::
mt19937
&
gen
)
:
PackItemCache
(
set
),
out
(
cards
),
gen
(
gen
)
{}
/// Generate a pack, adding it to cards
void
generate
(
const
PackType
&
pack
);
/// Number of cards of a type
typedef
map
<
pair
<
ScriptValueP
,
PackSelectType
>
,
int
>
OfTypeCount
;
/// Determine what *types* of cards to pick (store in out)
/** Does NOT add cards yet.
* Returns true if non-empty.
*/
bool
generateCount
(
const
PackType
&
pack
,
int
copies
,
PackSelectType
type
,
OfTypeCount
&
out
);
bool
generateCount
(
const
PackItem
&
item
,
int
copies
,
PackSelectType
type
,
OfTypeCount
&
out
);
bool
generateSingleCount
(
const
PackType
&
pack
,
PackSelectType
type
,
OfTypeCount
&
out
);
/// Pick cards from a list
void
pickCards
(
const
ScriptValueP
&
cards
,
PackSelectType
type
,
int
amount
);
/// The cards will be stored here
vector
<
CardP
>&
out
;
/// Random generator
boost
::
mt19937
&
gen
;
/// Details for each PackType
map
<
String
,
PackInstanceP
>
instances
;
int
max_depth
;
};
// ----------------------------------------------------------------------------- : EOF
...
...
src/gui/set/random_pack_panel.cpp
View file @
1cf4d1c8
...
...
@@ -88,10 +88,14 @@ void RandomCardList::getItems(vector<VoidP>& out) const {
class
PackTotalsPanel
:
public
wxPanel
{
public:
#if USE_NEW_PACK_SYSTEM
PackTotalsPanel
(
Window
*
parent
,
int
id
,
PackGenerator
&
generator
)
:
wxPanel
(
parent
,
id
),
generator
(
generator
)
{}
#else
PackTotalsPanel
(
Window
*
parent
,
int
id
)
:
wxPanel
(
parent
,
id
)
{}
#endif
void
setGame
(
const
GameP
&
game
);
void
clear
();
#if !USE_NEW_PACK_SYSTEM
void
clear
();
void
addPack
(
PackType
&
pack
,
int
copies
);
void
addItemRef
(
PackItemRef
&
item
,
int
copies
);
#endif
...
...
@@ -101,12 +105,11 @@ class PackTotalsPanel : public wxPanel {
void
onPaint
(
wxPaintEvent
&
);
void
draw
(
DC
&
dc
);
void
drawItem
(
DC
&
dc
,
int
&
y
,
const
String
&
name
,
double
value
);
#if USE_NEW_PACK_SYSTEM
public:
map
<
const
PackType
*
,
double
>
amounts
;
#else
#if USE_NEW_PACK_SYSTEM
PackGenerator
&
generator
;
#else
map
<
String
,
int
>
amounts
;
#endif
#endif
};
void
PackTotalsPanel
::
onPaint
(
wxPaintEvent
&
)
{
...
...
@@ -126,10 +129,10 @@ void PackTotalsPanel::draw(DC& dc) {
int
total
=
0
;
#if USE_NEW_PACK_SYSTEM
FOR_EACH
(
pack
,
game
->
pack_types
)
{
if
(
pack
->
summary
)
{
int
value
=
amounts
[
pack
.
get
()];
drawItem
(
dc
,
y
,
tr
(
*
game
,
pack
->
name
,
capitalize
),
value
);
total
+=
value
;
PackInstance
&
i
=
generator
.
get
(
pack
);
if
(
pack
->
summary
&&
i
.
has_cards
())
{
drawItem
(
dc
,
y
,
tr
(
*
game
,
pack
->
name
,
capitalize
),
i
.
get_card_copies
()
);
total
+=
(
int
)
i
.
get_card_copies
()
;
}
}
#else
...
...
@@ -160,12 +163,14 @@ void PackTotalsPanel::drawItem(DC& dc, int& y, const String& name, double value
void
PackTotalsPanel
::
setGame
(
const
GameP
&
game
)
{
this
->
game
=
game
;
#if !USE_NEW_PACK_SYSTEM
clear
();
}
void
PackTotalsPanel
::
clear
()
{
amounts
.
clear
();
#endif
}
#if !USE_NEW_PACK_SYSTEM
void
PackTotalsPanel
::
clear
()
{
amounts
.
clear
();
}
void
PackTotalsPanel
::
addPack
(
PackType
&
pack
,
int
copies
)
{
FOR_EACH
(
item
,
pack
.
items
)
{
addItemRef
(
*
item
,
copies
*
item
->
amount
);
...
...
@@ -196,7 +201,11 @@ void RandomPackPanel::initControls() {
seed_random
=
new
wxRadioButton
(
this
,
ID_SEED_RANDOM
,
_BUTTON_
(
"random seed"
));
seed_fixed
=
new
wxRadioButton
(
this
,
ID_SEED_FIXED
,
_BUTTON_
(
"fixed seed"
));
seed
=
new
wxTextCtrl
(
this
,
wxID_ANY
);
#if USE_NEW_PACK_SYSTEM
totals
=
new
PackTotalsPanel
(
this
,
wxID_ANY
,
generator
);
#else
totals
=
new
PackTotalsPanel
(
this
,
wxID_ANY
);
#endif
static_cast
<
SetWindow
*>
(
GetParent
())
->
setControlStatusText
(
seed_random
,
_HELP_
(
"random seed"
));
static_cast
<
SetWindow
*>
(
GetParent
())
->
setControlStatusText
(
seed_fixed
,
_HELP_
(
"fixed seed"
));
static_cast
<
SetWindow
*>
(
GetParent
())
->
setControlStatusText
(
seed
,
_HELP_
(
"seed"
));
...
...
@@ -259,6 +268,9 @@ void RandomPackPanel::onChangeSet() {
// add pack controls
FOR_EACH
(
pack
,
set
->
game
->
pack_types
)
{
#if NEW_PACK_SYSTEM
if
(
pack
->
selectable
)
{
#endif
PackItem
i
;
i
.
pack
=
pack
;
i
.
label
=
new
wxStaticText
(
this
,
wxID_ANY
,
capitalize_sentence
(
pack
->
name
));
...
...
@@ -266,6 +278,9 @@ void RandomPackPanel::onChangeSet() {
packsSizer
->
Add
(
i
.
label
,
0
,
wxALIGN_CENTER_VERTICAL
);
packsSizer
->
Add
(
i
.
value
,
0
,
wxEXPAND
|
wxALIGN_CENTER
);
packs
.
push_back
(
i
);
#if NEW_PACK_SYSTEM
}
#endif
}
Layout
();
...
...
@@ -280,6 +295,9 @@ void RandomPackPanel::onChangeSet() {
i
.
value
->
SetValue
(
gs
.
pack_amounts
[
i
.
pack
->
name
]);
}
#if USE_NEW_PACK_SYSTEM
generator
.
reset
(
set
,
0
);
#endif
updateTotals
();
}
...
...
@@ -328,20 +346,22 @@ void RandomPackPanel::onCommand(int id) {
// ----------------------------------------------------------------------------- : Generating
void
RandomPackPanel
::
updateTotals
()
{
#if USE_NEW_PACK_SYSTEM
PackItemCounter
counter
(
*
set
,
totals
->
amounts
);
#endif
#if !USE_NEW_PACK_SYSTEM
totals
->
clear
();
total_packs
=
0
;
#endif
int
total_packs
=
0
;
FOR_EACH
(
i
,
packs
)
{
int
copies
=
i
.
value
->
GetValue
();
total_packs
+=
copies
;
#if USE_NEW_PACK_SYSTEM
counter
.
addCountRecursive
(
*
i
.
pack
,
copies
);
generator
.
get
(
i
.
pack
).
request_copy
(
copies
);
#else
totals
->
addPack
(
*
i
.
pack
,
copies
);
#endif
}
#if USE_NEW_PACK_SYSTEM
generator
.
update_card_counts
();
#endif
// update UI
totals
->
Refresh
(
false
);
generate_button
->
Enable
(
total_packs
>
0
);
...
...
@@ -373,10 +393,10 @@ void RandomPackPanel::setSeed(int seed) {
}
void
RandomPackPanel
::
generate
()
{
boost
::
mt19937
gen
((
unsigned
)
getSeed
());
#if USE_NEW_PACK_SYSTEM
PackItemGenerator
generator
(
*
set
,
card_list
->
cards
,
gen
);
generator
.
reset
(
set
,
getSeed
()
);
#else
boost
::
mt19937
gen
((
unsigned
)
getSeed
());
PackItemCache
pack_cache
(
*
set
);
#endif
// add packs to card list
...
...
@@ -385,7 +405,8 @@ void RandomPackPanel::generate() {
int
copies
=
item
.
value
->
GetValue
();
for
(
int
i
=
0
;
i
<
copies
;
++
i
)
{
#if USE_NEW_PACK_SYSTEM
generator
.
generate
(
*
item
.
pack
);
generator
.
get
(
item
.
pack
).
request_copy
();
generator
.
generate
(
card_list
->
cards
);
#else
card_list
->
add
(
pack_cache
,
gen
,
*
item
.
pack
);
#endif
...
...
src/gui/set/random_pack_panel.hpp
View file @
1cf4d1c8
...
...
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
#include <data/pack.hpp>
#include <wx/spinctrl.h>
class
CardViewer
;
...
...
@@ -66,7 +67,9 @@ class RandomPackPanel : public SetWindowPanel {
};
vector
<
PackItem
>
packs
;
int
total_packs
;
#if USE_NEW_PACK_SYSTEM
PackGenerator
generator
;
#endif
/// Actual intialization of the controls
void
initControls
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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