From ac6b8f77ac0f6c15b722360bcafbe3d62cc39924 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 10 Jan 2009 20:22:11 +0000 Subject: [PATCH] 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 --- data/magic.mse-game/packs | 8 ++++---- src/data/pack.cpp | 35 +++++++++++++++++++---------------- src/data/pack.hpp | 4 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/data/magic.mse-game/packs b/data/magic.mse-game/packs index d9e9ab34..ef77ae82 100644 --- a/data/magic.mse-game/packs +++ b/data/magic.mse-game/packs @@ -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 diff --git a/src/data/pack.cpp b/src/data/pack.cpp index ad111969..027f0158 100644 --- a/src/data/pack.cpp +++ b/src/data/pack.cpp @@ -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* 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* 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* 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()) { diff --git a/src/data/pack.hpp b/src/data/pack.hpp index 6db30af8..e51d1527 100644 --- a/src/data/pack.hpp +++ b/src/data/pack.hpp @@ -157,7 +157,7 @@ class PackItem : public IntrusivePtrBase { String name; ///< Name of the pack to select cards from Scriptable amount; ///< Number of cards of this type - Scriptable probability; ///< Relative probability of picking this item + Scriptable 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 { int depth; //< 0 = no items, otherwise 1+max depth of items refered to vector 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;