mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Removed old random pack code. It was already disabled by the USE_NEW_PACK_SYSTEM flag.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1482 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -54,11 +54,7 @@ IMPLEMENT_REFLECTION(Game) {
|
||||
REFLECT_NO_SCRIPT(card_list_color_script);
|
||||
REFLECT_NO_SCRIPT(statistics_dimensions);
|
||||
REFLECT_NO_SCRIPT(statistics_categories);
|
||||
#if USE_NEW_PACK_SYSTEM
|
||||
REFLECT_ALIAS(308, "pack item", "pack type");
|
||||
#else
|
||||
REFLECT_NO_SCRIPT(pack_items);
|
||||
#endif
|
||||
REFLECT_NO_SCRIPT(pack_types);
|
||||
REFLECT_NO_SCRIPT(keyword_match_script);
|
||||
REFLECT(has_keywords);
|
||||
|
||||
@@ -14,14 +14,12 @@
|
||||
#include <script/scriptable.hpp>
|
||||
#include <script/dependency.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
#include <data/pack.hpp> // for USE_NEW_PACK_SYSTEM
|
||||
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
DECLARE_POINTER_TYPE(Game);
|
||||
DECLARE_POINTER_TYPE(StatsDimension);
|
||||
DECLARE_POINTER_TYPE(StatsCategory);
|
||||
DECLARE_POINTER_TYPE(PackItem);
|
||||
DECLARE_POINTER_TYPE(PackType);
|
||||
DECLARE_POINTER_TYPE(KeywordParam);
|
||||
DECLARE_POINTER_TYPE(KeywordMode);
|
||||
@@ -47,9 +45,6 @@ class Game : public Packaged {
|
||||
OptionalScript card_list_color_script; ///< Script that determines the color of items in the card list
|
||||
vector<StatsDimensionP> statistics_dimensions; ///< (Additional) statistics dimensions
|
||||
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
||||
#if !USE_NEW_PACK_SYSTEM
|
||||
vector<PackItemP> pack_items; ///< Types of cards in packs
|
||||
#endif
|
||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||
vector<WordListP> word_lists; ///< Word lists for editing with a drop down list
|
||||
vector<AddCardsScriptP> add_cards_scripts; ///< Scripts for adding multiple cards to the set
|
||||
|
||||
@@ -13,152 +13,6 @@
|
||||
#include <data/card.hpp>
|
||||
#include <queue>
|
||||
|
||||
#if !USE_NEW_PACK_SYSTEM
|
||||
// =================================================================================================== OLD
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(PackItemRefP);
|
||||
DECLARE_TYPEOF_COLLECTION(PackItemP);
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackType
|
||||
|
||||
PackType::PackType()
|
||||
: enabled(true)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION(PackType) {
|
||||
REFLECT(name);
|
||||
REFLECT(enabled);
|
||||
REFLECT(items);
|
||||
}
|
||||
|
||||
bool PackType::update(Context& ctx) {
|
||||
bool change = enabled.update(ctx);
|
||||
FOR_EACH(item, items) {
|
||||
change |= item->update(ctx);
|
||||
}
|
||||
return change;
|
||||
}
|
||||
|
||||
void PackType::generate(PackItemCache& packs, boost::mt19937& gen, vector<CardP>& out) const {
|
||||
FOR_EACH_CONST(item, items) {
|
||||
item->generate(packs,gen,out);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackRefType
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(PackRefType) {
|
||||
VALUE_N("replace", PACK_REF_REPLACE);
|
||||
VALUE_N("no replace", PACK_REF_NO_REPLACE);
|
||||
VALUE_N("cyclic", PACK_REF_CYCLIC);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItemRef
|
||||
|
||||
PackItemRef::PackItemRef()
|
||||
: amount(1)
|
||||
, type(PACK_REF_NO_REPLACE)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION(PackItemRef) {
|
||||
REFLECT(name);
|
||||
REFLECT(amount);
|
||||
REFLECT(type);
|
||||
}
|
||||
|
||||
bool PackItemRef::update(Context& ctx) {
|
||||
return amount.update(ctx);
|
||||
}
|
||||
|
||||
/// Random generator with random numbers in a range
|
||||
template <typename Gen>
|
||||
struct RandomRange {
|
||||
RandomRange(Gen& gen) : gen(gen) {}
|
||||
unsigned operator () (unsigned max) { return gen() % max; }
|
||||
Gen& gen;
|
||||
};
|
||||
|
||||
void PackItemRef::generate(PackItemCache& packs, boost::mt19937& gen, vector<CardP>& out) const {
|
||||
vector<CardP>& cards = packs.cardsFor(name);
|
||||
// generate 'amount' cards and add them to out
|
||||
if (cards.empty()) return;
|
||||
if (type == PACK_REF_REPLACE) {
|
||||
// amount random numbers
|
||||
for (int i = 0 ; i < amount ; ++i) {
|
||||
size_t index = gen() % cards.size();
|
||||
out.push_back(cards[index]);
|
||||
}
|
||||
} else if (type == PACK_REF_NO_REPLACE) {
|
||||
// random shuffle
|
||||
// to prevent us from being too predictable for small sets, periodically reshuffle
|
||||
RandomRange<boost::mt19937> gen_range(gen);
|
||||
size_t max_per_batch = (cards.size() + 1) / 2;
|
||||
int rem = amount;
|
||||
while (rem > 0) {
|
||||
random_shuffle(cards.begin(), cards.end(), gen_range);
|
||||
out.insert(out.end(), cards.begin(), cards.begin() + min((size_t)rem, max_per_batch));
|
||||
rem -= (int)max_per_batch;
|
||||
}
|
||||
} else if (type == PACK_REF_CYCLIC) {
|
||||
// multiple copies
|
||||
size_t copies = amount / cards.size();
|
||||
FOR_EACH_CONST(card, cards) {
|
||||
out.insert(out.end(),copies,card);
|
||||
}
|
||||
// TODO: what if amount is not a multiple of the number of cards?
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItem
|
||||
|
||||
IMPLEMENT_REFLECTION(PackItem) {
|
||||
REFLECT(name);
|
||||
REFLECT(filter);
|
||||
}
|
||||
|
||||
void PackItem::generate(Set& set, vector<CardP>& out) const {
|
||||
FOR_EACH(card, set.cards) {
|
||||
Context& ctx = set.getContext(card);
|
||||
bool keep = *filter.invoke(ctx);
|
||||
if (keep) {
|
||||
out.push_back(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItemCache
|
||||
|
||||
PackItemCache::PackItemCache(Set& set)
|
||||
: set(set)
|
||||
{}
|
||||
|
||||
vector<CardP>& PackItemCache::cardsFor(const String& name) {
|
||||
// lookup name
|
||||
map<String,Cards>::iterator it = item_cards.find(name);
|
||||
if (it != item_cards.end()) {
|
||||
return *it->second;
|
||||
} else {
|
||||
// not used before, generate list and cache
|
||||
FOR_EACH(item, set.game->pack_items) {
|
||||
if (item->name == name) {
|
||||
Cards cards(new vector<CardP>);
|
||||
item->generate(set,*cards);
|
||||
item_cards.insert(make_pair(name,cards));
|
||||
return *cards;
|
||||
}
|
||||
}
|
||||
// still not found
|
||||
throw Error(_ERROR_1_("pack item not found",name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
// =================================================================================================== NEW
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(PackTypeP);
|
||||
DECLARE_TYPEOF_COLLECTION(PackItemP);
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
@@ -588,5 +442,3 @@ void PackGenerator::update_card_counts() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,100 +15,6 @@
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/logic/tribool.hpp>
|
||||
|
||||
#define USE_NEW_PACK_SYSTEM 1
|
||||
|
||||
#if !USE_NEW_PACK_SYSTEM
|
||||
// =================================================================================================== OLD
|
||||
|
||||
DECLARE_POINTER_TYPE(PackItemRef);
|
||||
DECLARE_POINTER_TYPE(Card);
|
||||
class Set;
|
||||
class PackItemCache;
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackType
|
||||
|
||||
/// A card pack description for playtesting
|
||||
class PackType : public IntrusivePtrBase<PackType> {
|
||||
public:
|
||||
PackType();
|
||||
|
||||
String name; ///< Name of this pack
|
||||
Scriptable<bool> enabled; ///< Is this pack enabled?
|
||||
vector<PackItemRefP> items; ///< Cards in this pack
|
||||
|
||||
/// Update scripts, returns true if there is a change
|
||||
bool update(Context& ctx);
|
||||
|
||||
/// Generate a random pack of cards, add them to out
|
||||
void generate(PackItemCache& packs, boost::mt19937& gen, vector<CardP>& out) const;
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItemRef
|
||||
|
||||
enum PackRefType
|
||||
{ PACK_REF_REPLACE
|
||||
, PACK_REF_NO_REPLACE
|
||||
, PACK_REF_CYCLIC
|
||||
};
|
||||
|
||||
class PackItemRef : public IntrusivePtrBase<PackItemRef> {
|
||||
public:
|
||||
PackItemRef();
|
||||
|
||||
String name; ///< Name of this type of cards
|
||||
Scriptable<int> amount; ///< Number of cards of this type
|
||||
PackRefType type;
|
||||
|
||||
/// Update scripts, returns true if there is a change
|
||||
bool update(Context& ctx);
|
||||
|
||||
/// Generate random cards, add them to out
|
||||
void generate(PackItemCache& packs, boost::mt19937& gen, vector<CardP>& out) const;
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItem
|
||||
|
||||
/// A card type description for playtesting
|
||||
class PackItem : public IntrusivePtrBase<PackItem> {
|
||||
public:
|
||||
String name; ///< Name of this type of cards
|
||||
OptionalScript filter; ///< Filter to select this type of cards
|
||||
|
||||
/// Select *all* cards matching the filter
|
||||
void generate(Set& set, vector<CardP>& out) const;
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackItemCache
|
||||
|
||||
class PackItemCache {
|
||||
public:
|
||||
PackItemCache(Set& set);
|
||||
|
||||
/// The cards for a given PackItem
|
||||
vector<CardP>& cardsFor(const String& name);
|
||||
|
||||
private:
|
||||
Set& set;
|
||||
/// Cards for each PackItem
|
||||
typedef shared_ptr<vector<CardP> > Cards;
|
||||
map<String,Cards> item_cards;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
// =================================================================================================== NEW
|
||||
|
||||
DECLARE_POINTER_TYPE(PackType);
|
||||
DECLARE_POINTER_TYPE(PackItem);
|
||||
DECLARE_POINTER_TYPE(PackInstance);
|
||||
@@ -240,4 +146,3 @@ class PackGenerator {
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <data/pack.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/field/text.hpp> // for 0.2.7 fix
|
||||
#include <data/field/information.hpp>
|
||||
|
||||
Reference in New Issue
Block a user