mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
while there is still time to make changes to the file format: s/probability/weight/
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1338 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+19
-16
@@ -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 probabilities
|
||||
total_probability = cards.size();
|
||||
// Sum of weights
|
||||
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()) {
|
||||
|
||||
+2
-2
@@ -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 probabilities
|
||||
double total_weight; //< Sum of item and card weights
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user