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
a24df85a
Commit
a24df85a
authored
Jan 10, 2009
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
while there is still time to make changes to the file format: s/probability/weight/
parent
aa820659
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
22 deletions
+25
-22
data/magic.mse-game/packs
data/magic.mse-game/packs
+4
-4
src/data/pack.cpp
src/data/pack.cpp
+19
-16
src/data/pack.hpp
src/data/pack.hpp
+2
-2
No files found.
data/magic.mse-game/packs
View file @
a24df85a
...
...
@@ -91,10 +91,10 @@ pack type:
select: proportional
item:
name: mythic rare
probability
: 1
weight
: 1
item:
name: rare
probability
: 2
weight
: 2
pack type:
name: shifted uncommon or rare
...
...
@@ -102,10 +102,10 @@ pack type:
select: nonempty
item:
name: shifted uncommon
probability
: 3
weight
: 3
item:
name: shifted rare
probability
: 1
weight
: 1
############################################################## Common proportions of cards
...
...
src/data/pack.cpp
View file @
a24df85a
...
...
@@ -207,7 +207,7 @@ IMPLEMENT_REFLECTION(PackItem) {
}
else
{
REFLECT
(
name
);
REFLECT
(
amount
);
REFLECT
(
probability
);
REFLECT
(
weight
);
}
}
...
...
@@ -221,13 +221,13 @@ PackType::PackType()
PackItem
::
PackItem
()
:
amount
(
1
)
,
probability
(
1
)
,
weight
(
1
)
{}
PackItem
::
PackItem
(
const
String
&
name
,
int
amount
)
:
name
(
name
)
,
amount
(
amount
)
,
probability
(
1
)
,
weight
(
1
)
{}
...
...
@@ -241,7 +241,7 @@ bool PackType::update(Context& ctx) {
bool
PackItem
::
update
(
Context
&
ctx
)
{
return
amount
.
update
(
ctx
)
|
probability
.
update
(
ctx
);
|
weight
.
update
(
ctx
);
}
...
...
@@ -281,17 +281,17 @@ PackInstance::PackInstance(const PackType& pack_type, PackGenerator& parent)
count
+=
parent
.
get
(
item
->
name
).
count
;
}
}
// Sum of
probabilitie
s
total_
probability
=
cards
.
size
();
// Sum of
weight
s
total_
weight
=
cards
.
size
();
FOR_EACH_CONST
(
item
,
pack_type
.
items
)
{
if
(
pack_type
.
select
==
SELECT_PROPORTIONAL
)
{
total_
probability
+=
item
->
probability
*
parent
.
get
(
item
->
name
).
count
;
total_
weight
+=
item
->
weight
*
parent
.
get
(
item
->
name
).
count
;
}
else
if
(
pack_type
.
select
==
SELECT_NONEMPTY
)
{
if
(
parent
.
get
(
item
->
name
).
count
>
0
)
{
total_
probability
+=
item
->
probability
;
total_
weight
+=
item
->
weight
;
}
}
else
{
total_
probability
+=
item
->
probability
;
total_
weight
+=
item
->
weight
;
}
}
// Depth
...
...
@@ -309,10 +309,10 @@ void PackInstance::expect_copy(double copies) {
if
(
pack_type
.
select
==
SELECT_ALL
)
{
i
.
expect_copy
(
copies
*
item
->
amount
);
}
else
if
(
pack_type
.
select
==
SELECT_PROPORTIONAL
)
{
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
probability
*
i
.
count
/
total_probability
);
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
weight
*
i
.
count
/
total_weight
);
}
else
if
(
pack_type
.
select
==
SELECT_NONEMPTY
)
{
if
(
i
.
count
>
0
)
{
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
probability
/
total_probability
);
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
weight
/
total_weight
);
}
}
else
if
(
pack_type
.
select
==
SELECT_FIRST
)
{
if
(
i
.
count
>
0
&&
cards
.
empty
())
{
...
...
@@ -320,7 +320,7 @@ void PackInstance::expect_copy(double copies) {
break
;
}
}
else
{
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
probability
/
total_probability
);
i
.
expect_copy
(
copies
*
item
->
amount
*
item
->
weight
/
total_weight
);
}
}
}
...
...
@@ -359,7 +359,7 @@ void PackInstance::generate(vector<CardP>* out) {
||
pack_type
.
select
==
SELECT_NONEMPTY
)
{
// multiple copies
for
(
size_t
i
=
0
;
i
<
requested_copies
;
++
i
)
{
double
r
=
parent
.
gen
()
*
total_
probability
/
parent
.
gen
.
max
();
double
r
=
parent
.
gen
()
*
total_
weight
/
parent
.
gen
.
max
();
if
(
r
<
cards
.
size
())
{
// pick a card
card_copies
++
;
...
...
@@ -373,11 +373,11 @@ void PackInstance::generate(vector<CardP>* out) {
FOR_EACH_CONST
(
item
,
pack_type
.
items
)
{
PackInstance
&
i
=
parent
.
get
(
item
->
name
);
if
(
pack_type
.
select
==
SELECT_REPLACE
)
{
r
-=
item
->
probability
;
r
-=
item
->
weight
;
}
else
if
(
pack_type
.
select
==
SELECT_PROPORTIONAL
)
{
r
-=
item
->
probability
*
i
.
count
;
r
-=
item
->
weight
*
i
.
count
;
}
else
{
// SELECT_NONEMPTY
if
(
i
.
count
>
0
)
r
-=
item
->
probability
;
if
(
i
.
count
>
0
)
r
-=
item
->
weight
;
}
// have we reached the item we were looking for?
if
(
r
<
0
)
{
...
...
@@ -389,6 +389,9 @@ void PackInstance::generate(vector<CardP>* out) {
}
}
else
if
(
pack_type
.
select
==
SELECT_NO_REPLACE
)
{
if
(
!
pack_type
.
items
.
empty
())
{
throw
Error
(
_
(
"'select:no replace' is not yet supported in combination with 'items', only with 'filter'."
));
}
card_copies
+=
requested_copies
;
// NOTE: there is no way to pick items without replacement
if
(
out
&&
!
cards
.
empty
())
{
...
...
src/data/pack.hpp
View file @
a24df85a
...
...
@@ -157,7 +157,7 @@ class PackItem : public IntrusivePtrBase<PackItem> {
String
name
;
///< Name of the pack to select cards from
Scriptable
<
int
>
amount
;
///< Number of cards of this type
Scriptable
<
double
>
probability
;
///< Relative probability of picking this item
Scriptable
<
double
>
weight
;
///< Relative probability of picking this item
/// Update scripts, returns true if there is a change
bool
update
(
Context
&
ctx
);
...
...
@@ -201,7 +201,7 @@ class PackInstance : public IntrusivePtrBase<PackInstance> {
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 probabilitie
s
double
total_
weight
;
//< Sum of item and card weight
s
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
;
...
...
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