Fixes for exclusion/inclusion combinations of colors or abilities.

This commit is contained in:
wrenczes
2011-04-28 05:01:06 +00:00
parent 7e4364b484
commit 8610531bf3
6 changed files with 94 additions and 82 deletions

View File

@@ -11,7 +11,6 @@
#define CD_OR 1 #define CD_OR 1
#define CD_AND 2 #define CD_AND 2
#define CD_NOT 3
enum ENUM_COMPARISON_MODES enum ENUM_COMPARISON_MODES
{ {
@@ -59,6 +58,11 @@ class CardDescriptor: public MTGCardInstance
MTGCardInstance * match(MTGGameZone * zone); MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous); MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
void SetExclusionColor(int _color, int removeAllOthers = 0);
uint8_t mColorExclusions;
BasicAbilitiesSet mAbilityExclusions;
int nameComparisonMode; int nameComparisonMode;
int colorComparisonMode; int colorComparisonMode;
string compareName; string compareName;

View File

@@ -36,7 +36,8 @@ public:
int init(); int init();
uint8_t colors; uint8_t colors;
std::bitset<Constants::NB_BASIC_ABILITIES> basicAbilities; typedef std::bitset<Constants::NB_BASIC_ABILITIES> BasicAbilitiesSet;
BasicAbilitiesSet basicAbilities;
map<string,string> magicTexts; map<string,string> magicTexts;
string magicText; string magicText;
@@ -61,6 +62,8 @@ public:
bool hasColor(int inColor); bool hasColor(int inColor);
int countColors(); int countColors();
static uint8_t ConvertColorToBitMask(int inColor);
int has(int ability); int has(int ability);
void setText(const string& value); void setText(const string& value);

View File

@@ -4,7 +4,8 @@
#include "Subtypes.h" #include "Subtypes.h"
#include "Counters.h" #include "Counters.h"
CardDescriptor::CardDescriptor() : MTGCardInstance() CardDescriptor::CardDescriptor()
: MTGCardInstance(), mColorExclusions(0)
{ {
init(); init();
counterName = ""; counterName = "";
@@ -101,12 +102,6 @@ bool CardDescriptor::valueInRange(int comparisonMode, int value, int criterion)
return false; return false;
} }
MTGCardInstance* CardDescriptor::match_not(MTGCardInstance * card)
{
// if we have a color match, return null
bool colorFound = (colors & card->colors) > 0;
return colorFound ? NULL : card;
}
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card) MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card)
{ {
@@ -138,10 +133,16 @@ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card)
if (colors) if (colors)
{ {
found = (colors & card->colors); found = (colors & card->colors);
if (!found)
return NULL;
} }
if (!found) if (mColorExclusions)
return NULL; {
found = mColorExclusions & card->colors;
if (found)
return NULL;
}
// Quantified restrictions are always AND-ed: // Quantified restrictions are always AND-ed:
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power)) if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power))
@@ -178,6 +179,12 @@ MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card)
if ((colors & card->colors) != colors) if ((colors & card->colors) != colors)
match = NULL; match = NULL;
if (mColorExclusions)
{
if ((mColorExclusions & card->colors) == mColorExclusions)
match = NULL;
}
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power)) if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power))
match = NULL; match = NULL;
if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness)) if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness))
@@ -202,24 +209,16 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card)
{ {
match = match_or(card); match = match_or(card);
} }
else
{
match = match_not(card);
}
//Abilities //Abilities
std::bitset<Constants::NB_BASIC_ABILITIES> set = basicAbilities & card->basicAbilities; BasicAbilitiesSet set = basicAbilities & card->basicAbilities;
if (set != basicAbilities)
return NULL;
BasicAbilitiesSet excludedSet = mAbilityExclusions & card->basicAbilities;
if (excludedSet.any())
return NULL;
if (mode == CD_NOT)
{
if (set.any())
return NULL;
}
else
{
if (set != basicAbilities)
return NULL;
}
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped())) if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped()))
{ {
@@ -389,3 +388,11 @@ MTGCardInstance * CardDescriptor::nextmatch(MTGGameZone * zone, MTGCardInstance
} }
return NULL; return NULL;
} }
void CardDescriptor::SetExclusionColor(int _color, int removeAllOthers)
{
if (removeAllOthers)
mColorExclusions = 0;
mColorExclusions |= ConvertColorToBitMask(_color);
}

View File

@@ -258,13 +258,13 @@ void CardGui::Render()
mFont->SetScale(1); mFont->SetScale(1);
} }
} }
if (tc && !tc->canTarget(card)) //if (tc && !tc->canTarget(card))
{ //{
if (!shadow) // if (!shadow)
shadow = WResourceManager::Instance()->GetQuad("shadow"); // shadow = WResourceManager::Instance()->GetQuad("shadow");
shadow->SetColor(ARGB(200,255,255,255)); // shadow->SetColor(ARGB(200,255,255,255));
renderer->RenderQuad(shadow.get(), actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16); // renderer->RenderQuad(shadow.get(), actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
} //}
PlayGuiObject::Render(); PlayGuiObject::Render();
} }

View File

@@ -11,46 +11,6 @@ using std::string;
namespace namespace
{ {
uint8_t ConvertColorToBitMask(int inColor)
{
uint8_t value = 0;
switch (inColor)
{
case Constants::MTG_COLOR_ARTIFACT:
value = kColorBitMask_Artifact;
break;
case Constants::MTG_COLOR_GREEN:
value = kColorBitMask_Green;
break;
case Constants::MTG_COLOR_BLUE:
value = kColorBitMask_Blue;
break;
case Constants::MTG_COLOR_RED:
value = kColorBitMask_Red;
break;
case Constants::MTG_COLOR_BLACK:
value = kColorBitMask_Black;
break;
case Constants::MTG_COLOR_WHITE:
value = kColorBitMask_White;
break;
case Constants::MTG_COLOR_LAND:
value = kColorBitMask_Land;
break;
default:
break;
}
return value;
}
/** /**
** Count the number of set bits in a given integer ** Count the number of set bits in a given integer
*/ */
@@ -381,3 +341,43 @@ int CardPrimitive::getToughness()
{ {
return toughness; return toughness;
} }
uint8_t CardPrimitive::ConvertColorToBitMask(int inColor)
{
uint8_t value = 0;
switch (inColor)
{
case Constants::MTG_COLOR_ARTIFACT:
value = kColorBitMask_Artifact;
break;
case Constants::MTG_COLOR_GREEN:
value = kColorBitMask_Green;
break;
case Constants::MTG_COLOR_BLUE:
value = kColorBitMask_Blue;
break;
case Constants::MTG_COLOR_RED:
value = kColorBitMask_Red;
break;
case Constants::MTG_COLOR_BLACK:
value = kColorBitMask_Black;
break;
case Constants::MTG_COLOR_WHITE:
value = kColorBitMask_White;
break;
case Constants::MTG_COLOR_LAND:
value = kColorBitMask_Land;
break;
default:
break;
}
return value;
}

View File

@@ -576,10 +576,9 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
attributefound = 1; attributefound = 1;
if (minus) if (minus)
{ cd->SetExclusionColor(cid);
cd->mode = CD_NOT; else
} cd->setColor(cid);
cd->setColor(cid);
} }
} }
if (!attributefound) if (!attributefound)
@@ -591,10 +590,9 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
attributefound = 1; attributefound = 1;
if (minus) if (minus)
{ cd->mAbilityExclusions.set(j);
cd->mode = CD_NOT; else
} cd->basicAbilities.set(j);
cd->basicAbilities.set(j);
} }
} }
} }
@@ -613,7 +611,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
} }
} }
} }
if (nbminuses && cd->mode != CD_NOT) if (nbminuses)
cd->mode = CD_AND; cd->mode = CD_AND;
typeName = typeName.substr(0, found); typeName = typeName.substr(0, found);
} }