- Magic 2010 - blockers ordering
- Fixed a memory leak introduced in a previous revision (foreach)
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-07-04 04:15:05 +00:00
parent dfeada17a2
commit d52f06d98d
22 changed files with 580 additions and 253 deletions

View File

@@ -1,32 +1,32 @@
#include "../include/config.h"
#include "../include/Blocker.h"
Blocker::Blocker(int id, MTGCardInstance * card):MTGAbility(id, card){
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card):MTGAbility(id, card){
init ( NEW ManaCost());
}
Blocker::Blocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
init(_cost);
}
Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target):MTGAbility(id, card,_target){
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, MTGCardInstance *_target):MTGAbility(id, card,_target){
init ( NEW ManaCost());
}
Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
UntapBlocker::UntapBlocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost);
}
Blocker::~Blocker(){
UntapBlocker::~UntapBlocker(){
SAFE_DELETE(manaCost);
}
void Blocker::init(ManaCost * _cost){
void UntapBlocker::init(ManaCost * _cost){
currentPhase = -1;
manaCost = _cost;
}
//Default behaviour for blockers : they block the card they're attached to
void Blocker::Update(float dt){
void UntapBlocker::Update(float dt){
game = GameObserver::GetInstance();
int newPhase = game->getCurrentGamePhase();
if (newPhase != currentPhase){
@@ -36,7 +36,7 @@ void Blocker::Update(float dt){
}else{
_target = source;
}
_target->getBlockers()->Add(this);
_target->getUntapBlockers()->Add(this);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName());
@@ -46,24 +46,24 @@ void Blocker::Update(float dt){
currentPhase = newPhase;
}
int Blocker::destroy(){
int UntapBlocker::destroy(){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Remove(this);
_target->getUntapBlockers()->Remove(this);
return 1;
}
Blockers::Blockers(){
UntapBlockers::UntapBlockers(){
init();
}
int Blockers::init(){
int UntapBlockers::init(){
cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){
@@ -73,25 +73,25 @@ int Blockers::init(){
return 1;
}
int Blockers::Add (Blocker * ability){
int UntapBlockers::Add (UntapBlocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1;
return index;
}
int Blockers::Remove (Blocker * ability){
int UntapBlockers::Remove (UntapBlocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0;
return index;
}
int Blockers::rewind(){
int UntapBlockers::rewind(){
cursor = -1;
return 1;
}
Blocker * Blockers::next(){
UntapBlocker * UntapBlockers::next(){
cursor++;
game = GameObserver::GetInstance();
while (blockers[cursor] == 0){
@@ -101,12 +101,12 @@ Blocker * Blockers::next(){
return NULL;
}
}
return (Blocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
return (UntapBlocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
}
int Blockers::isEmpty(){
int UntapBlockers::isEmpty(){
for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i])
return 0;
@@ -114,6 +114,6 @@ int Blockers::isEmpty(){
return 1;
}
Blockers::~Blockers(){
UntapBlockers::~UntapBlockers(){
}