- Adding cycling. Check Akroma's vengeance in ONS for an example. Note that this uses autohand instead of auto, this is important! You can also use autograveyard. 
- All "auto" activated abilities should work with autohand, so this is not only for cycling, but could be used for other abilities as well. For example autohand={3}:cycling can also be written autohand={3}{S}:Draw:1
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-12-12 11:09:13 +00:00
parent 3d23a4f3c8
commit 512f649147
15 changed files with 164 additions and 30 deletions
+1 -1
View File
@@ -214,7 +214,7 @@ int AIAction::getEfficiency(){
}
break;
}
if (p->game->hand->nb_cards == 0) efficiency *= 1.3; //increase chance of using ability if hand is empty
if (p->game->hand->nb_cards == 0) efficiency = (int) ((float) efficiency * 1.3); //increase chance of using ability if hand is empty
return efficiency;
}
+1 -1
View File
@@ -163,7 +163,7 @@ void AIStats::Render(){
MTGCard * card = GameApp::collection->getCardById(stat->source);
if (card) {
sprintf(buffer, "%s %i", card->getName().c_str(), stat->value);
f->DrawString(buffer,x0+5,10 + 16 *i);
f->DrawString(buffer,x0+5,10 + 16 *(float)i);
i++;
}
}
+1
View File
@@ -27,6 +27,7 @@ void DuelLayers::init(){
action->Add(NEW MTGPersistRule(-1));
action->Add(NEW MTGLifelinkRule(-1));
action->Add(NEW MTGDeathtouchRule(-1));
action->Add(NEW OtherAbilitiesEventReceiver(-1));
//Other display elements
action->Add(NEW HUDDisplay(-1));
+35 -12
View File
@@ -145,12 +145,10 @@ TriggeredAbility * AbilityFactory::parseTrigger(string magicText, int id, Spell
//Parses a string and returns the corresponding MTGAbility object
// Returns NULL if parsing failed
//Beware, Spell CAN be null when the function is called by the AI trying to analyze the effects of a given card
MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated, int forceUEOT){
MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated, int forceUEOT, MTGGameZone * dest){
size_t found;
string whitespaces (" \t\f\v\n\r");
@@ -240,8 +238,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
tc = tcf.createTargetChooser(starget, card);
}
if (tc) return NEW GenericTargetAbility(id, card, tc, a,cost, doTap,limit,myTurnOnly);
return NEW GenericActivatedAbility(id, card, a,cost,doTap,limit,myTurnOnly);
if (tc) return NEW GenericTargetAbility(id, card, tc, a,cost, doTap,limit,myTurnOnly,dest);
return NEW GenericActivatedAbility(id, card, a,cost,doTap,limit,myTurnOnly,dest);
}
SAFE_DELETE(cost);
}
@@ -362,6 +360,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
return NULL;
}
//Cycling
found = s.find("cycling");
if (found != string::npos){
MTGAbility * a = NEW ACycle(id,card,target);
a->oneShot = 1;
return a;
}
//Fizzle (counterspell...)
found = s.find("fizzle");
@@ -842,14 +847,32 @@ int AbilityFactory::computeX(Spell * spell, MTGCardInstance * card){
}
int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card, int id){
int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card, int id, MTGGameZone * dest){
if (!card && spell) card = spell->source;
if (!card) return 0;
MTGCardInstance * target = card->target;
if (!target) target = card;
string magicText = card->magicText;
if (card->alias && magicText.size() == 0){
string magicText;
if (dest) {
GameObserver * g = GameObserver::GetInstance();
for (int i = 0; i < 2 ; ++i){
MTGPlayerCards * zones = g->players[i]->game;
if (dest == zones->hand){
magicText = card->magicTexts["hand"];
break;
}
if (dest == zones->graveyard){
magicText = card->magicTexts["graveyard"];
break;
}
//Other zones needed ?
return 0;
}
}else{
magicText = card->magicText;
}
if (card->alias && magicText.size() == 0 && !dest){
MTGCard * c = GameApp::collection->getCardById(card->alias);
if (!c) return 0;
magicText = c->magicText;
@@ -870,7 +893,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
magicText = "";
}
MTGAbility * a = parseMagicLine(line, result, spell, card);
MTGAbility * a = parseMagicLine(line, result, spell, card,0,0,dest);
if (a){
v->push_back(a);
result++;
@@ -890,12 +913,12 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
* - target (if there ie a "target(" in the string, then this is a TargetAbility)
* - doTap (a dirty way to know if tapping is included in the cost...
*/
int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int mode, TargetChooser * tc){
int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int mode, TargetChooser * tc,MTGGameZone * dest){
int dryMode = 0;
if (!spell) dryMode = 1;
if (!spell && !dest) dryMode = 1;
vector<MTGAbility *> v;
int result = getAbilities(&v,spell,card,id);
int result = getAbilities(&v,spell,card,id,dest);
for (size_t i = 0; i < v.size(); ++i){
MTGAbility * a = v[i];
+10
View File
@@ -46,6 +46,9 @@ MTGCard::MTGCard(MTGCard * source){
mtgid = source->mtgid;
setId = source->setId;
magicText = source->magicText;
for(map<string,string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it){
magicTexts[it->first] = source->magicTexts[it->first];
}
spellTargetType = source->spellTargetType;
alias = source->alias;
}
@@ -63,6 +66,7 @@ int MTGCard::init(){
setId = 0;
mtgid = 0;
magicText = "";
magicTexts.clear();
spellTargetType = "";
alias = 0;
rarity = Constants::RARITY_C;
@@ -260,6 +264,12 @@ void MTGCard::addMagicText(string value){
magicText.append(value);
}
void MTGCard::addMagicText(string value, string key){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
if (magicTexts[key].size()) magicTexts[key].append("\n");
magicTexts[key].append(value);
}
void MTGCard::setName( string value){
name = value;
lcname = value;
+3
View File
@@ -30,6 +30,9 @@ int MTGAllCards::processConfLine(string s, MTGCard *card){
if(key.compare( "auto")==0){
card->addMagicText(value);
}
else if(key.find("auto") == 0){
card->addMagicText(value,key.substr(4));
}
else if(key.compare( "alias")==0){
card->alias=atoi(value.c_str());
}
+30
View File
@@ -164,6 +164,36 @@ ostream& MTGAttackRule::toString(ostream& out) const
}
OtherAbilitiesEventReceiver::OtherAbilitiesEventReceiver(int _id):MTGAbility(_id,NULL){
}
int OtherAbilitiesEventReceiver::receiveEvent(WEvent *e){
if (WEventZoneChange* event = dynamic_cast<WEventZoneChange*>(e)) {
if (event->to && (event->to != event->from)){
GameObserver * g = GameObserver::GetInstance();
for (int i = 0; i < 2; ++i){
if (event->to == g->players[i]->game->inPlay) return 0;
}
AbilityFactory af;
af.magicText(g->mLayers->actionLayer()->getMaxId(), NULL, event->card, 1, 0,event->to);
return 1;
}
}
return 0;
}
int OtherAbilitiesEventReceiver::testDestroy(){
return 0;
}
OtherAbilitiesEventReceiver * OtherAbilitiesEventReceiver::clone() const{
OtherAbilitiesEventReceiver * a = NEW OtherAbilitiesEventReceiver(*this);
a->isClone = 1;
return a;
}
MTGBlockRule::MTGBlockRule(int _id):MTGAbility(_id,NULL){
aType=MTGAbility::MTG_BLOCK_RULE;
}