* Some cleaning of the ^M's
* Fix a few warnings
This commit is contained in:
jean.chalard
2008-11-17 16:54:18 +00:00
parent 7363dcccd4
commit 8f282e8eae
+223 -223
View File
@@ -14,67 +14,67 @@ int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2 ; i++){ for (int i = 0; i < 2 ; i++){
if (player && player!= game->players[i]) continue; if (player && player!= game->players[i]) continue;
for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){ for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
if (tc->canTarget(current)){ if (tc->canTarget(current)){
switch (option){ switch (option){
case COUNT_POWER: case COUNT_POWER:
result+= current->power; result+= current->power;
break; break;
default: default:
result++; result++;
break; break;
} }
} }
} }
} }
return result; return result;
} }
int AbilityFactory::destroyAllInPlay(TargetChooser * tc, int bury){ int AbilityFactory::destroyAllInPlay(TargetChooser * tc, int bury){
tc->source = NULL; // This is to prevent protection from... as objects that destroy all do not actually target tc->source = NULL; // This is to prevent protection from... as objects that destroy all do not actually target
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2 ; i++){ for (int i = 0; i < 2 ; i++){
for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){ for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
if (tc->canTarget(current)){ if (tc->canTarget(current)){
if (bury){ if (bury){
game->players[i]->game->putInGraveyard(current); game->players[i]->game->putInGraveyard(current);
}else{ }else{
game->mLayers->stackLayer()->addPutInGraveyard(current); game->mLayers->stackLayer()->addPutInGraveyard(current);
}
}
}
} }
return 1; }
}
}
return 1;
} }
int AbilityFactory::putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p){ int AbilityFactory::putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p){
Spell * spell = NEW Spell(card); Spell * spell = NEW Spell(card);
p->game->putInZone(card, zone, p->game->stack); p->game->putInZone(card, zone, p->game->stack);
spell->resolve(); spell->resolve();
delete spell; delete spell;
return 1; return 1;
} }
Trigger * AbilityFactory::parseTrigger(string magicText){ Trigger * AbilityFactory::parseTrigger(string magicText){
int found = magicText.find("@"); size_t found = magicText.find("@");
if (found == string::npos) return NULL; if (found == string::npos) return NULL;
//Next Time... //Next Time...
found = magicText.find("next"); found = magicText.find("next");
if (found != string::npos){ if (found != string::npos){
for (int i = 0; i < NB_MTG_PHASES; i++){ for (int i = 0; i < NB_MTG_PHASES; i++){
found = magicText.find(MTGPhaseCodeNames[i]); found = magicText.find(MTGPhaseCodeNames[i]);
if (found != string::npos){ if (found != string::npos){
return NEW TriggerNextPhase(i); return NEW TriggerNextPhase(i);
} }
} }
} }
return NULL; return NULL;
} }
//Some basic functionalities that can be added automatically in the text file //Some basic functionalities that can be added automatically in the text file
@@ -87,210 +87,210 @@ Trigger * AbilityFactory::parseTrigger(string magicText){
* - doTap (a dirty way to know if tapping is included in the cost... * - doTap (a dirty way to know if tapping is included in the cost...
*/ */
int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
int dryMode = 0; int dryMode = 0;
if (!spell) dryMode = 1; if (!spell) dryMode = 1;
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (!card) card = spell->source; if (!card) card = spell->source;
MTGCardInstance * target = card->target; MTGCardInstance * target = card->target;
if (!target) target = card; if (!target) target = card;
string magicText = card->magicText; string magicText = card->magicText;
if (card->alias && magicText.size() == 0){ if (card->alias && magicText.size() == 0){
//An awful way to get access to the aliasedcard //An awful way to get access to the aliasedcard
magicText = GameObserver::GetInstance()->players[0]->game->collection->getCardById(card->alias)->magicText; magicText = GameObserver::GetInstance()->players[0]->game->collection->getCardById(card->alias)->magicText;
} }
string s; string s;
int size = magicText.size(); int size = magicText.size();
if (size == 0) return 0; if (size == 0) return 0;
unsigned int found; unsigned int found;
int result = id; int result = id;
while (magicText.size()){ while (magicText.size()){
found = magicText.find("\n"); found = magicText.find("\n");
if (found != string::npos){ if (found != string::npos){
s = magicText.substr(0,found); s = magicText.substr(0,found);
magicText = magicText.substr(found+1); magicText = magicText.substr(found+1);
}else{ }else{
s = magicText; s = magicText;
magicText = ""; magicText = "";
} }
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "AUTO ACTION: %s\n", s.c_str()); sprintf(buf, "AUTO ACTION: %s\n", s.c_str());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
TargetChooser * tc = NULL; TargetChooser * tc = NULL;
int doTap = 0; int doTap = 0;
string lordType = ""; string lordType = "";
Trigger * trigger = parseTrigger(s); Trigger * trigger = parseTrigger(s);
//Dirty way to remove the trigger text (could get in the way) //Dirty way to remove the trigger text (could get in the way)
if (trigger){ if (trigger){
found = s.find(":"); found = s.find(":");
s = s.substr(found+1); s = s.substr(found+1);
} }
//Tap in the cost ? //Tap in the cost ?
if (s.find("{t}") != string::npos) doTap = 1; if (s.find("{t}") != string::npos) doTap = 1;
//Target Abilities //Target Abilities
found = s.find("target("); found = s.find("target(");
if (found != string::npos){ if (found != string::npos){
int end = s.find(")"); int end = s.find(")");
string starget = s.substr(found + 7,end - found - 7); string starget = s.substr(found + 7,end - found - 7);
TargetChooserFactory tcf; TargetChooserFactory tcf;
tc = tcf.createTargetChooser(starget, card); tc = tcf.createTargetChooser(starget, card);
} }
//Lord //Lord
found = s.find("lord("); found = s.find("lord(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) return BAKA_EFFECT_GOOD;
unsigned int end = s.find(")", found+5); unsigned int end = s.find(")", found+5);
if (end != string::npos){ if (end != string::npos){
lordType = s.substr(found+5,end-found-5).c_str(); lordType = s.substr(found+5,end-found-5).c_str();
} }
} }
//Champion. Very basic, needs to be improved ! //Champion. Very basic, needs to be improved !
found = s.find("champion(name:"); found = s.find("champion(name:");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) return BAKA_EFFECT_GOOD;
unsigned int end = s.find(")", found+14); unsigned int end = s.find(")", found+14);
if (end != string::npos){ if (end != string::npos){
string type = s.substr(found+14,end-found-14).c_str(); string type = s.substr(found+14,end-found-14).c_str();
game->addObserver(NEW APlagueRats(id,card,type.c_str())); game->addObserver(NEW APlagueRats(id,card,type.c_str()));
result++; result++;
continue; continue;
} }
} }
//Untapper (Ley Druid...) //Untapper (Ley Druid...)
found = s.find("untap"); found = s.find("untap");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) return BAKA_EFFECT_GOOD;
ManaCost * cost = ManaCost::parseManaCost(s); ManaCost * cost = ManaCost::parseManaCost(s);
if (tc){ if (tc){
game->addObserver(NEW AUntaper(id, card, cost, tc)); game->addObserver(NEW AUntaper(id, card, cost, tc));
}else{ }else{
target->tapped = 0; target->tapped = 0;
} }
result++; result++;
continue; continue;
} }
//Tapper (icy manipulator) //Tapper (icy manipulator)
found = s.find("tap"); found = s.find("tap");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) return BAKA_EFFECT_GOOD;
ManaCost * cost = ManaCost::parseManaCost(s); ManaCost * cost = ManaCost::parseManaCost(s);
if (tc){ if (tc){
game->addObserver(NEW ATapper(id, card, cost, tc)); game->addObserver(NEW ATapper(id, card, cost, tc));
}else{ }else{
target->tapped = 1; target->tapped = 1;
} }
result++; result++;
continue; continue;
} }
//Regeneration //Regeneration
found = s.find("}:regenerate"); found = s.find("}:regenerate");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) return BAKA_EFFECT_GOOD;
ManaCost * cost = ManaCost::parseManaCost(s); ManaCost * cost = ManaCost::parseManaCost(s);
if (lordType.size() > 0){ if (lordType.size() > 0){
game->addObserver(NEW ALord(id,card,lordType.c_str(),0,0,-1,cost)); game->addObserver(NEW ALord(id,card,lordType.c_str(),0,0,-1,cost));
}else{ }else{
if (tc){ if (tc){
//TODO //TODO
}else{ }else{
game->addObserver(NEW AStandardRegenerate(id, card, target, cost)); game->addObserver(NEW AStandardRegenerate(id, card, target, cost));
//TODO death ward ! //TODO death ward !
} }
} }
result++; result++;
continue; continue;
} }
//Bury //Bury
found = s.find("bury"); found = s.find("bury");
if (found != string::npos){ if (found != string::npos){
if (trigger){ if (trigger){
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode) return BAKA_EFFECT_BAD;
BuryEvent * action = NEW BuryEvent(); BuryEvent * action = NEW BuryEvent();
game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action)); game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action));
}else{ }else{
found = s.find("all("); found = s.find("all(");
if (found != string::npos){ if (found != string::npos){
int end = s.find(")"); int end = s.find(")");
string starget = s.substr(found + 4,end - found - 4); string starget = s.substr(found + 4,end - found - 4);
TargetChooserFactory tcf; TargetChooserFactory tcf;
TargetChooser * targetAll = tcf.createTargetChooser(starget, card); TargetChooser * targetAll = tcf.createTargetChooser(starget, card);
if (dryMode){ if (dryMode){
int myNbCards = countCards(targetAll,card->controller()); int myNbCards = countCards(targetAll,card->controller());
int opponentNbCards = countCards(targetAll, card->controller()->opponent()); int opponentNbCards = countCards(targetAll, card->controller()->opponent());
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER); int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER); int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll; delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD; if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD; return BAKA_EFFECT_BAD;
}else{ }else{
this->destroyAllInPlay(targetAll,1); this->destroyAllInPlay(targetAll,1);
delete targetAll; delete targetAll;
} }
}else{ }else{
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode) return BAKA_EFFECT_BAD;
if (tc){ if (tc){
game->addObserver(NEW ABurier(id, card,tc)); game->addObserver(NEW ABurier(id, card,tc));
}else{ }else{
target->controller()->game->putInGraveyard(target); target->controller()->game->putInGraveyard(target);
} }
} }
} }
result++; result++;
continue; continue;
} }
//Destroy //Destroy
found = s.find("destroy"); found = s.find("destroy");
if (found != string::npos){ if (found != string::npos){
found = s.find("all("); found = s.find("all(");
if (found != string::npos){ if (found != string::npos){
int end = s.find(")"); int end = s.find(")");
string starget = s.substr(found + 4,end - found - 4); string starget = s.substr(found + 4,end - found - 4);
TargetChooserFactory tcf; TargetChooserFactory tcf;
TargetChooser * targetAll = tcf.createTargetChooser(starget, card); TargetChooser * targetAll = tcf.createTargetChooser(starget, card);
if (dryMode){ if (dryMode){
int myNbCards = countCards(targetAll,card->controller()); int myNbCards = countCards(targetAll,card->controller());
int opponentNbCards = countCards(targetAll, card->controller()->opponent()); int opponentNbCards = countCards(targetAll, card->controller()->opponent());
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER); int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER); int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll; delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD; if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD; return BAKA_EFFECT_BAD;
}else{ }else{
this->destroyAllInPlay(targetAll); this->destroyAllInPlay(targetAll);
delete targetAll; delete targetAll;
} }
}else{ }else{
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode) return BAKA_EFFECT_BAD;
if (tc){ if (tc){
game->addObserver(NEW ADestroyer(id, card,tc)); game->addObserver(NEW ADestroyer(id, card,tc));
}else{ }else{
game->mLayers->stackLayer()->addPutInGraveyard(target); game->mLayers->stackLayer()->addPutInGraveyard(target);
} }
} }
result++; result++;
continue; continue;
} }
//Damage //Damage
found = s.find("damage"); found = s.find("damage");