* added hashmap for all basic abilities.
* created three new utility functions that return a vector of matching abilities, colors and types
* migrated all activated ability impl into AllAbilities.cpp. Perhaps we could break AllAbilities up into separate impl files for manageability?
One for Activated abilities, another for triggers,etc
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -217,10 +217,14 @@ class Constants
|
||||
static const char* MTGColorStrings[];
|
||||
static int _r[], _g[], _b[];
|
||||
|
||||
|
||||
static map<string,int> MTGBasicAbilitiesMap;
|
||||
static const char* MTGBasicAbilities[];
|
||||
static const char* MTGPhaseNames[];
|
||||
static const char* MTGPhaseCodeNames[];
|
||||
|
||||
static int GetBasicAbilityIndex(string mtgAbility);
|
||||
static int GetColorStringIndex(string mtgColor);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,6 +43,10 @@ std::vector<std::string> &split(const std::string &s, char delim, std::vector<st
|
||||
std::vector<std::string> split(const std::string &s, char delim); //splits a string with "delim" and returns a vector of strings.
|
||||
std::string wordWrap(std::string s, int width);
|
||||
|
||||
void PopulateColorIndexVector( list<int>& colors, const string& colorsString, char delimiter = ' ');
|
||||
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilitiesString, char delimiter = ',');
|
||||
void PopulateSubtypesIndexVector( list<int>& subtypes, const string& subtypesString, char delimiter = ' ');
|
||||
|
||||
|
||||
int loadRandValues(string s);
|
||||
int filesize(const char * filename);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1154,25 +1154,25 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
||||
//Bury, destroy, sacrifice, reject(discard)
|
||||
if (s.find("bury") != string::npos)
|
||||
{
|
||||
MTGAbility *a = NEW AABuryCard(id, card, target, NULL, AABanishCard::BURY);
|
||||
MTGAbility *a = NEW AABuryCard(id, card, target, AABanishCard::BURY);
|
||||
a->oneShot = 1;
|
||||
return a;
|
||||
}
|
||||
else if (s.find("destroy") != string::npos)
|
||||
{
|
||||
MTGAbility * a = NEW AADestroyCard(id, card, target, NULL, AABanishCard::DESTROY);
|
||||
MTGAbility * a = NEW AADestroyCard(id, card, target, AABanishCard::DESTROY);
|
||||
a->oneShot = 1;
|
||||
return a;
|
||||
}
|
||||
else if (s.find("sacrifice") != string::npos)
|
||||
{
|
||||
MTGAbility *a = NEW AASacrificeCard(id, card, target, NULL, AABanishCard::SACRIFICE);
|
||||
MTGAbility *a = NEW AASacrificeCard(id, card, target, AABanishCard::SACRIFICE);
|
||||
a->oneShot = 1;
|
||||
return a;
|
||||
}
|
||||
else if (s.find("reject") != string::npos)
|
||||
{
|
||||
MTGAbility *a = NEW AADiscardCard(id, card, target, NULL, AABanishCard::DISCARD);
|
||||
MTGAbility *a = NEW AADiscardCard(id, card, target, AABanishCard::DISCARD);
|
||||
a->oneShot = 1;
|
||||
return a;
|
||||
}
|
||||
@@ -1712,19 +1712,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
||||
size_t end = s.find(",", found);
|
||||
if (end == string::npos)
|
||||
end = real_end;
|
||||
string stypes = s.substr(found + 11, end - found - 11);
|
||||
string sabilities;
|
||||
if (end != real_end)
|
||||
{
|
||||
int previous = end + 1;
|
||||
if (end == string::npos)
|
||||
end = real_end;
|
||||
string temp = s.substr(previous, end - previous);
|
||||
}
|
||||
if (end != real_end)
|
||||
{
|
||||
sabilities = s.substr(end + 1, real_end - end);
|
||||
}
|
||||
size_t stypesStartIndex = found + 11;
|
||||
string transformsParamsString = s.substr(stypesStartIndex, real_end - stypesStartIndex);
|
||||
vector<string> effectParameters = split( transformsParamsString, ',');
|
||||
string stypes = effectParameters[0];
|
||||
|
||||
string sabilities = transformsParamsString.substr(stypes.length());
|
||||
|
||||
MTGAbility * a;
|
||||
if (forceFOREVER)
|
||||
{
|
||||
|
||||
@@ -93,6 +93,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
attribute = value;
|
||||
value = "";
|
||||
}
|
||||
|
||||
for (int j = Constants::NB_BASIC_ABILITIES - 1; j >= 0; --j)
|
||||
{
|
||||
size_t found = attribute.find(Constants::MTGBasicAbilities[j]);
|
||||
|
||||
@@ -25,7 +25,6 @@ const string Constants::kFlashBackKeyword = "flashback";
|
||||
const string Constants::kRetraceKeyword = "retrace";
|
||||
const string Constants::kKickerKeyword = "kicker";
|
||||
|
||||
|
||||
const char* Constants::MTGBasicAbilities[] = {
|
||||
"trample",
|
||||
"forestwalk",
|
||||
@@ -113,6 +112,33 @@ const char* Constants::MTGBasicAbilities[] = {
|
||||
"exiledeath",
|
||||
};
|
||||
|
||||
map<string,int> Constants::MTGBasicAbilitiesMap;
|
||||
int Constants::GetBasicAbilityIndex(string basicAbllity)
|
||||
{
|
||||
if ( Constants::MTGBasicAbilitiesMap.size() == 0 )
|
||||
{
|
||||
for (int idx = 0; idx < Constants::NB_BASIC_ABILITIES; ++idx)
|
||||
{
|
||||
string ability = MTGBasicAbilities[idx];
|
||||
MTGBasicAbilitiesMap[ability] = idx;
|
||||
}
|
||||
}
|
||||
if ( Constants::MTGBasicAbilitiesMap.find(basicAbllity) != Constants::MTGBasicAbilitiesMap.end() )
|
||||
return Constants::MTGBasicAbilitiesMap[basicAbllity];
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Constants::GetColorStringIndex(string mtgColor)
|
||||
{
|
||||
for (int idx = 0; idx < Constants::MTG_NB_COLORS; ++idx)
|
||||
{
|
||||
if (Constants::MTGColorStrings[idx])
|
||||
return idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* Constants::MTGPhaseNames[] =
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "MTGDefinitions.h"
|
||||
#include "Subtypes.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
@@ -259,3 +261,41 @@ std::string wordWrap(std::string sentence, int width)
|
||||
|
||||
return sentence;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilityStringList, char delimiter )
|
||||
{
|
||||
vector<string> abilitiesList = split( abilityStringList, delimiter);
|
||||
for ( vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter)
|
||||
{
|
||||
int abilityIndex = Constants::GetBasicAbilityIndex( *iter );
|
||||
|
||||
if (abilityIndex != -1)
|
||||
abilities.push_back( abilityIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void PopulateColorIndexVector( list<int>& colors, const string& colorStringList, char delimiter )
|
||||
{
|
||||
vector<string> abilitiesList = split( colorStringList, delimiter);
|
||||
for ( vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter)
|
||||
{
|
||||
int colorIndex = Constants::GetColorStringIndex(*iter);
|
||||
|
||||
if (colorIndex != -1)
|
||||
colors.push_back(colorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void PopulateSubtypesIndexVector( list<int>& types, const string& subTypesStringList, char delimiter)
|
||||
{
|
||||
vector<string> subTypesList = split( subTypesStringList, delimiter);
|
||||
for (vector<string>::iterator it = subTypesList.begin(); it != subTypesList.end(); ++it)
|
||||
{
|
||||
string subtype = *it;
|
||||
size_t id = Subtypes::subtypesList->find( subtype );
|
||||
if ( id != string::npos )
|
||||
types.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user