-fix issue 297
- also removed the "untapBlockers" system. The idea was nice but incorrectly implemented, and only 2 cards were using it so far.
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-01-17 12:05:40 +00:00
parent 6830d850f2
commit ffbcd3f2d0
16 changed files with 74 additions and 306 deletions
-125
View File
@@ -1,125 +0,0 @@
#include "../include/config.h"
#include "../include/Blocker.h"
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card):MTGAbility(id, card){
init ( NEW ManaCost());
}
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
init(_cost);
}
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, MTGCardInstance *_target):MTGAbility(id, card,_target){
init ( NEW ManaCost());
}
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost);
}
UntapBlocker::~UntapBlocker(){
SAFE_DELETE(manaCost);
}
void UntapBlocker::init(ManaCost * _cost){
currentPhase = -1;
manaCost = _cost;
}
UntapBlocker * UntapBlocker::clone() const{
UntapBlocker * a = NEW UntapBlocker(*this);
a->isClone = 1;
return a;
}
//Default behaviour for blockers : they block the card they're attached to
void UntapBlocker::Update(float dt){
game = GameObserver::GetInstance();
int newPhase = game->getCurrentGamePhase();
if (newPhase != currentPhase){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getUntapBlockers()->Add(this);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->getName().c_str());
OutputDebugString(buf);
#endif
}
currentPhase = newPhase;
}
int UntapBlocker::destroy(){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getUntapBlockers()->Remove(this);
return 1;
}
UntapBlockers::UntapBlockers(){
init();
}
int UntapBlockers::init(){
cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0;
}
return 1;
}
int UntapBlockers::Add (UntapBlocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1;
return index;
}
int UntapBlockers::Remove (UntapBlocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0;
return index;
}
int UntapBlockers::rewind(){
cursor = -1;
return 1;
}
UntapBlocker * UntapBlockers::next(){
cursor++;
game = GameObserver::GetInstance();
while (blockers[cursor] == 0){
cursor ++;
if (cursor == MAX_BLOCKERS){
cursor = -1;
return NULL;
}
}
return (UntapBlocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
}
int UntapBlockers::isEmpty(){
for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i])
return 0;
}
return 1;
}
UntapBlockers::~UntapBlockers(){
}
-1
View File
@@ -19,7 +19,6 @@ int CardDescriptor::init(){
defenser = NULL;
banding = NULL;
//Remove unnecessary pointers
SAFE_DELETE(untapBlockers);
SAFE_DELETE(counters);
SAFE_DELETE(previous);
return result;
-42
View File
@@ -1,42 +0,0 @@
#include "../include/config.h"
#include "../include/ConstraintResolver.h"
int ConstraintResolver::untap(GameObserver * game, MTGCardInstance * card){
if (!card->isUntapping()){
return 0;
}
if (card->has(Constants::DOESNOTUNTAP)) return 0;
int ok = 1;
ManaCost * untapManaCost = NEW ManaCost();
UntapBlockers * blockers = card->getUntapBlockers();
UntapBlocker * blocker;
blockers->rewind();
Player * player = game->currentPlayer;
while ((blocker = blockers->next())){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "next\n");
OutputDebugString(buf);
#endif
untapManaCost->add(blocker->untapManaCost());
}
if (player->getManaPool()->canAfford(untapManaCost)){
blockers->rewind();
while ((blocker = blockers->next())){
if (!blocker->unblock()){
ok = 0;
break;
}
}
}else{
ok = 0;
}
if (ok) {
player->getManaPool()->pay(untapManaCost);
card->attemptUntap();
}
delete untapManaCost;
return ok;
}
+12 -1
View File
@@ -435,7 +435,7 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
mLayers->actionLayer()->setMenuObject(object);
}
}else if (card->isTapped() && card->controller() == currentPlayer){
ConstraintResolver::untap(this, card);
untap(card);
}
@@ -443,6 +443,17 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
}
int GameObserver::untap(MTGCardInstance * card) {
if (!card->isUntapping()){
return 0;
}
if (card->has(Constants::DOESNOTUNTAP)) return 0;
card->attemptUntap();
return 1;
}
TargetChooser * GameObserver::getCurrentTargetChooser(){
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
if (_tc) return _tc;
+22 -20
View File
@@ -147,14 +147,18 @@ int AbilityFactory::parseRestriction(string s){
if (s.find("myturnonly") != string::npos) return ActivatedAbility::PLAYER_TURN_ONLY;
if (s.find("assorcery") != string::npos) return ActivatedAbility::AS_SORCERY;
size_t found = s.find("my");
if (found !=string::npos){
for (int i = 0; i < Constants::NB_MTG_PHASES; i++){
string toFind = "my";
toFind.append(Constants::MTGPhaseCodeNames[i]).append("only");
found = s.find(toFind);
if (found != string::npos){
return ActivatedAbility::MY_BEFORE_BEGIN + i;
string types[] = {"my","opponent", ""};
int starts[] = {ActivatedAbility::MY_BEFORE_BEGIN,ActivatedAbility::OPPONENT_BEFORE_BEGIN,ActivatedAbility::BEFORE_BEGIN};
for (int j = 0; j < 3; ++j){
size_t found = s.find(types[j]);
if (found !=string::npos){
for (int i = 0; i < Constants::NB_MTG_PHASES; i++){
string toFind = types[j];
toFind.append(Constants::MTGPhaseCodeNames[i]).append("only");
found = s.find(toFind);
if (found != string::npos){
return starts[j] + i;
}
}
}
}
@@ -1206,12 +1210,8 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
game->addObserver(NEW AConvertLandToCreatures(id, card, "forest"));
break;
}
case 1124: //Mana Vault
case 1124: //Mana Vault (the rest is softcoded!)
{
int output[] = {Constants::MTG_COLOR_ARTIFACT, 3};
game->addObserver(NEW AManaProducer(_id,card,card,NEW ManaCost(output,1)));
int cost[] = {Constants::MTG_COLOR_ARTIFACT, 4};
game->addObserver(NEW AUntapManaBlocker(_id+1, card, NEW ManaCost(cost,1)));
game->addObserver(NEW ARegularLifeModifierAura(_id+2, card, card, Constants::MTG_PHASE_DRAW, -1, 1));
break;
}
@@ -1336,13 +1336,6 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
}
break;
}
case 1171: //Paralyze
{
int cost[] = {Constants::MTG_COLOR_ARTIFACT, 4};
game->addObserver(NEW AUntapManaBlocker(_id, card,card->target, NEW ManaCost(cost,1)));
card->target->tap();
break;
}
case 1172: //Pestilence
{
game->addObserver(NEW APestilence(_id, card));
@@ -1736,6 +1729,15 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
if (cPhase != restrictions - MY_BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN) return 0;
}
if (restrictions>= OPPONENT_BEFORE_BEGIN && restrictions <= OPPONENT_AFTER_EOT){
if (player == game->currentPlayer) return 0;
if (cPhase != restrictions - OPPONENT_BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN) return 0;
}
if (restrictions>= BEFORE_BEGIN && restrictions <= AFTER_EOT){
if (cPhase != restrictions - BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN) return 0;
}
if (card == source && source->controller()==player && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness()))){
if (!cost) return 1;
if (!mana) mana = player->getManaPool();
-7
View File
@@ -81,7 +81,6 @@ void MTGCardInstance::copy(MTGCardInstance * card){
MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(untapBlockers);
SAFE_DELETE(counters);
SAFE_DELETE(previous);
LOG("==Deleting MTGCardInstance Succesfull==");
@@ -102,7 +101,6 @@ void MTGCardInstance::initMTGCI(){
doDamageTest = 1;
belongs_to=NULL;
tapped = 0;
untapBlockers = NULL;
untapping = 0;
summoningSickness = 1;
target = NULL;
@@ -159,11 +157,6 @@ int MTGCardInstance::removeType(int id, int removeAll){
return result;
}
UntapBlockers * MTGCardInstance::getUntapBlockers(){
if (!untapBlockers) untapBlockers = NEW UntapBlockers();
return untapBlockers;
}
int MTGCardInstance::isInPlay(){
GameObserver * game = GameObserver::GetInstance();
for (int i = 0 ; i < 2 ; i++){
+1 -1
View File
@@ -338,7 +338,7 @@ void MTGInPlay::untapAll(){
for (i = 0; i < nb_cards; i ++){
MTGCardInstance * card = cards[i];
card->setUntapping();
if (!card->basicAbilities[Constants::DOESNOTUNTAP] && card->getUntapBlockers()->isEmpty()){
if (!card->basicAbilities[Constants::DOESNOTUNTAP]){
card->attemptUntap();
}
}