Jeck - First doxygen commit, basic information on WFilter classes. Also added filter price adjustment for some of the newer basic abilities (the CANTLOSE varieties now cost more to filter).

This commit is contained in:
wagic.jeck
2011-01-30 11:14:36 +00:00
parent 329b0cf929
commit e0f7bf26d8
3 changed files with 1837 additions and 6 deletions

1720
projects/mtg/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,24 @@
#ifndef _WFILTER_H_ #ifndef _WFILTER_H_
#define _WFILTER_H_ #define _WFILTER_H_
/**
@file WFilter.h
Includes classes and functionality related to card filtering.
@defgroup Filter Card filtering
@{
*/
class WCardFilter; class WCardFilter;
/**
A factory class used to construct a WCardFilter from a string. It does so via
recursive calls to Leaf(), which handles the structure of the filter, and Terminal(),
which handles specific filter components.
*/
class WCFilterFactory class WCFilterFactory
{ {
public: public:
WCFilterFactory(){}; WCFilterFactory() {};
static WCFilterFactory * GetInstance(); static WCFilterFactory * GetInstance();
static void Destroy(); static void Destroy();
WCardFilter * Construct(string src); WCardFilter * Construct(string src);
@@ -17,17 +29,34 @@ private:
static WCFilterFactory * me; static WCFilterFactory * me;
}; };
/**
An abstract parent to all filter components. Children provide implementations of
isMatch() to filter cards, and filterFee() to adjust card prices based on filtering.
*/
class WCardFilter class WCardFilter
{ {
public: public:
WCardFilter() {}; WCardFilter() {};
virtual ~WCardFilter() {}; virtual ~WCardFilter() {};
/**
Returns true if the card argument matches a certain condition.
*/
virtual bool isMatch(MTGCard * c) virtual bool isMatch(MTGCard * c)
{ {
return true; return true;
} }
; ;
/**
Returns the filter in the same string form used by WCFilterFactory to construct it.
*/
virtual string getCode() = 0; virtual string getCode() = 0;
/**
Returns a price multiplier which is summed using some logic (see the WCFBranch classes). Once a
multiplier has been figured, it is added to the card's base price in GameStateShop::purchasePrice(),
using the following equation: price + (price * filterFee * ((countAllCards - countMatchFilter)/countAllCards).
*/
virtual float filterFee() virtual float filterFee()
{ {
return 0.0f; return 0.0f;
@@ -35,6 +64,9 @@ public:
; ;
}; };
/**
An abstract parent to all filter logical branches.
*/
class WCFBranch: public WCardFilter class WCFBranch: public WCardFilter
{ {
public: public:
@@ -66,6 +98,10 @@ protected:
WCardFilter *lhs, *rhs; WCardFilter *lhs, *rhs;
}; };
/**
Handles the logical inclusive OR operator.
When returning a filterFee, it returns whichever is higher.
*/
class WCFilterOR: public WCFBranch class WCFilterOR: public WCFBranch
{ {
public: public:
@@ -79,6 +115,10 @@ public:
float filterFee(); float filterFee();
}; };
/**
Handles the logical inclusive AND operator.
When returning a filterFee, it returns the sum of the two filters.
*/
class WCFilterAND: public WCFBranch class WCFilterAND: public WCFBranch
{ {
public: public:
@@ -96,6 +136,10 @@ public:
float filterFee(); float filterFee();
}; };
/**
Logical group operator.
*/
class WCFilterGROUP: public WCardFilter class WCFilterGROUP: public WCardFilter
{ {
public: public:
@@ -124,6 +168,10 @@ protected:
WCardFilter * kid; WCardFilter * kid;
}; };
/**
A logical negation, returns true if the child filter returns false.
*/
class WCFilterNOT: public WCardFilter class WCFilterNOT: public WCardFilter
{ {
public: public:
@@ -147,6 +195,10 @@ protected:
WCardFilter * kid; WCardFilter * kid;
}; };
/**
An empty filter, matches anything. Used when WCFilterFactory is passed an empty string,
or cannot parse the syntax of something.
*/
class WCFilterNULL: public WCardFilter class WCFilterNULL: public WCardFilter
{ {
public: public:
@@ -166,7 +218,9 @@ public:
; ;
}; };
//Filter terminals: /**
Matches a card against a particular set.
*/
class WCFilterSet: public WCardFilter class WCFilterSet: public WCardFilter
{ {
public: public:
@@ -190,6 +244,10 @@ public:
protected: protected:
int setid; int setid;
}; };
/**
Matches a card that contains a particular letter.
*/
class WCFilterLetter: public WCardFilter class WCFilterLetter: public WCardFilter
{ {
public: public:
@@ -198,12 +256,16 @@ public:
string getCode(); string getCode();
float filterFee() float filterFee()
{ {
return 4.0f; return 4.0f; //Alpha searches are expensive!
} }
; //Alpha searches are expensive! ;
protected: protected:
char alpha; char alpha;
}; };
/**
Matches a card that contains a particular color (inclusively).
*/
class WCFilterColor: public WCardFilter class WCFilterColor: public WCardFilter
{ {
public: public:
@@ -223,6 +285,10 @@ public:
protected: protected:
int color; int color;
}; };
/**
Matches a card that is a particular color (exclusively).
*/
class WCFilterOnlyColor: public WCFilterColor class WCFilterOnlyColor: public WCFilterColor
{ {
public: public:
@@ -231,6 +297,10 @@ public:
bool isMatch(MTGCard * c); bool isMatch(MTGCard * c);
string getCode(); string getCode();
}; };
/**
Matches a card that produces mana of a particular color (inclusively).
*/
class WCFilterProducesColor: public WCFilterColor class WCFilterProducesColor: public WCFilterColor
{ {
public: public:
@@ -239,6 +309,10 @@ public:
bool isMatch(MTGCard * c); bool isMatch(MTGCard * c);
string getCode(); string getCode();
}; };
/**
The base class to all filters which compare a numeric value.
*/
class WCFilterNumeric: public WCardFilter class WCFilterNumeric: public WCardFilter
{ {
public: public:
@@ -254,6 +328,10 @@ public:
protected: protected:
int number; int number;
}; };
/**
Matches a card with a given combined mana cost.
*/
class WCFilterCMC: public WCFilterNumeric class WCFilterCMC: public WCFilterNumeric
{ {
public: public:
@@ -267,6 +345,10 @@ public:
} }
; ;
}; };
/**
Matches a card with a given power.
*/
class WCFilterPower: public WCFilterNumeric class WCFilterPower: public WCFilterNumeric
{ {
public: public:
@@ -280,6 +362,10 @@ public:
} }
; ;
}; };
/**
Matches a card with a given toughness.
*/
class WCFilterToughness: public WCFilterNumeric class WCFilterToughness: public WCFilterNumeric
{ {
public: public:
@@ -294,6 +380,9 @@ public:
; ;
}; };
/**
Matches a card of a given type (inclusively).
*/
class WCFilterType: public WCardFilter class WCFilterType: public WCardFilter
{ {
public: public:
@@ -312,6 +401,11 @@ public:
protected: protected:
string type; string type;
}; };
/**
Matches a card of a given rarity. If passed 'A' for any rarity, will always return true.
*/
class WCFilterRarity: public WCardFilter class WCFilterRarity: public WCardFilter
{ {
public: public:
@@ -327,6 +421,11 @@ public:
protected: protected:
char rarity; char rarity;
}; };
/**
Matches a card of a given basic ability.
*/
class WCFilterAbility: public WCardFilter class WCFilterAbility: public WCardFilter
{ {
public: public:
@@ -343,4 +442,5 @@ protected:
int ability; int ability;
}; };
/**@} This comment used by Doxyyen. */
#endif #endif

View File

@@ -435,11 +435,19 @@ string WCFilterAbility::getCode()
return buf; return buf;
} }
; ;
float WCFilterAbility::filterFee() float WCFilterAbility::filterFee()
{ {
switch (ability) switch (ability)
{ {
case Constants::CANTLOSE:
return 2.0f;
case Constants::CANTLIFELOSE:
case Constants::CANTMILLLOSE:
return 1.5f;
case Constants::SHROUD: case Constants::SHROUD:
case Constants::CONTROLLERSHROUD:
case Constants::PLAYERSHROUD:
case Constants::DEATHTOUCH: case Constants::DEATHTOUCH:
case Constants::UNBLOCKABLE: case Constants::UNBLOCKABLE:
case Constants::WITHER: case Constants::WITHER:
@@ -491,8 +499,11 @@ float WCFilterAND::filterFee()
} }
float WCFilterOR::filterFee() float WCFilterOR::filterFee()
{ {
if (lhs->filterFee() > rhs->filterFee()) return lhs->filterFee(); float lFee = lhs->filterFee();
return rhs->filterFee(); float rFee = rhs->filterFee();
if (lFee > rFee)
return lFee;
return rFee;
} }
string WCFilterNOT::getCode() string WCFilterNOT::getCode()
{ {