-fixesRockslide Elemental, Welkin Hawk
-Added messages for Manapool updates
-Cleaned up ManaProducer code
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-08-26 14:30:24 +00:00
parent 5e18cdb25d
commit 0dfa3f2e16
17 changed files with 165 additions and 144 deletions

View File

@@ -154,6 +154,7 @@ resurrection.txt
rhox_meditant.txt
rhox_meditant2.txt
righteous_cause.txt
rockslide_elemental.txt
rootwalla.txt
royal_assassin.txt
safehold_duo.txt
@@ -184,6 +185,7 @@ tranquil_domain.txt
volcanic_island.txt
wall_of_diffusion.txt
wall_of_diffusion2.txt
welkin_hawk.txt
white_knight1.txt
wrath_of_god.txt
zombie_master.txt

View File

@@ -0,0 +1,17 @@
#Bug: Crash when Rockslide elemental goes to graveyard
[INIT]
FIRSTMAIN
[PLAYER1]
inplay:rockslide elemental
manapool:{R}
hand:shock
[PLAYER2]
[DO]
shock
rockslide elemental
[ASSERT]
FIRSTMAIN
[PLAYER1]
graveyard:shock,rockslide elemental
[PLAYER2]
[END]

View File

@@ -0,0 +1,18 @@
#Bug: Crash whenWelki hawk goes to graveyard
[INIT]
FIRSTMAIN
[PLAYER1]
inplay:welkin hawk
manapool:{R}
hand:shock
[PLAYER2]
[DO]
shock
welkin hawk
choice 1
[ASSERT]
FIRSTMAIN
[PLAYER1]
graveyard:shock,welkin hawk
[PLAYER2]
[END]

View File

@@ -150,10 +150,14 @@ public:
}
int testDestroy(){
if (triggered && !game->mLayers->actionLayer()->menuObject && game->mLayers->actionLayer()->getIndexOf(mClone) ==-1){
if (triggered){
if (game->mLayers->actionLayer()->menuObject) return 0;
if (game->mLayers->actionLayer()->getIndexOf(mClone) !=-1) return 0;
if (game->mLayers->actionLayer()->getIndexOf(this) !=-1) return 0;
OutputDebugString("Destroy!\n");
return 1;
}
return 0;
}
@@ -172,11 +176,12 @@ public:
}
~MayAbility(){
if (!isClone) SAFE_DELETE(ability);
SAFE_DELETE(ability);
}
MayAbility * clone() const{
MayAbility * a = NEW MayAbility(*this);
a->ability = ability->clone();
a->isClone = 1;
return a;
}
@@ -292,8 +297,13 @@ public:
counters = 0;
}
~GenericTargetAbility(){
if (isClone) SAFE_DELETE(ability);
}
GenericTargetAbility * clone() const{
GenericTargetAbility * a = NEW GenericTargetAbility(*this);
a->ability = ability->clone();
a->isClone = 1;
return a;
}

View File

@@ -221,28 +221,18 @@ class AManaProducer: public MTGAbility{
string menutext;
float x0,y0,x1,y1,x,y;
float animation;
Player * controller;
hgeParticleSystem * mParticleSys;
public:
ManaCost * output;
int tap;
static int currentlyTapping;
AManaProducer(int id, MTGCardInstance * card, ManaCost * _output, ManaCost * _cost = NULL, int doTap = 1 );
void Update(float dt);
void Render();
int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL);
int resolve();
int destroy();
int reactToClick(MTGCardInstance * _card);
const char * getMenuText();
int testDestroy();
~AManaProducer();
virtual AManaProducer * clone() const;
virtual ostream& toString(ostream& out) const;
};
#include "MTGCardInstance.h"

View File

@@ -10,6 +10,7 @@ class ExtraCosts;
class ExtraCost;
class MTGAbility;
class MTGCardInstance;
class Player;
class ManaCost{
protected:
@@ -21,7 +22,7 @@ class ManaCost{
public:
ExtraCosts * extraCosts;
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
void init();
virtual void init();
void x();
ManaCost(int _cost[], int nb_elems = 1);
ManaCost();
@@ -66,4 +67,17 @@ class ManaCost{
std::ostream& operator<<(std::ostream& out, const ManaCost& m);
class ManaPool:public ManaCost{
protected:
Player * player;
public:
void init();
ManaPool(Player * player);
ManaPool(ManaCost * _manaCost, Player * player);
int remove (int color, int value);
int add(int color, int value, MTGCardInstance * source = NULL);
int add(ManaCost * _cost, MTGCardInstance * source = NULL);
int pay (ManaCost * _cost);
};
#endif

View File

@@ -2,17 +2,17 @@
#define _PLAYER_H_
#include "JGE.h"
#include "ManaCost.h"
#include "MTGGameZones.h"
#include "Damage.h"
#include "Targetable.h"
class MTGPlayerCards;
class MTGInPlay;
class ManaPool;
class Player: public Damageable{
protected:
ManaCost * manaPool;
ManaPool * manaPool;
public:
virtual void End();
@@ -28,7 +28,7 @@ class Player: public Damageable{
virtual ~Player();
void unTapPhase();
MTGInPlay * inPlay();
ManaCost * getManaPool();
ManaPool * getManaPool();
void cleanupPhase();
virtual int Act(float dt){return 0;};
virtual int isAI(){return 0;};

View File

@@ -6,6 +6,7 @@ class MTGGameZone;
class Damage;
class Phase;
class Targetable;
class ManaPool;
class WEvent{
public:
@@ -87,14 +88,23 @@ struct WEventCreatureBlockerRank: public WEventCardUpdate{
struct WEventEngageMana : public WEvent {
int color;
MTGCardInstance* card;
WEventEngageMana(int color, MTGCardInstance* card);
ManaPool * destination;
WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination);
};
//Event when a mana is consumed
//color : color
struct WEventConsumeMana : public WEvent {
int color;
WEventConsumeMana(int color);
ManaPool * source;
WEventConsumeMana(int color, ManaPool * source);
};
//Event when a manapool is emptied
//color : color
struct WEventEmptyManaPool : public WEvent {
ManaPool * source;
WEventEmptyManaPool(ManaPool * source);
};
#endif

View File

@@ -736,7 +736,7 @@ int AIPlayerBaka::Act(float dt){
oldGamePhase = currentGamePhase;
timer-= dt;
if (AManaProducer::currentlyTapping || timer>0){
if (timer>0){
return 0;
}
initTimer();

View File

@@ -235,8 +235,10 @@ void ActionLayer::doReactTo(int menuIndex){
char buf[4096];
sprintf(buf, "doReact To %i\n",controlid);
OutputDebugString(buf);
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
if (controlid != -1){
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
}
menuObject = 0;
}
}

View File

@@ -145,10 +145,10 @@ int GuiMana::receiveEventPlus(WEvent* e)
{
if (WEventEngageMana *event = dynamic_cast<WEventEngageMana*>(e))
{
if (event->card->view)
manas.push_back(NEW ManaIcon(event->color, event->card->view->actX, event->card->view->actY));
if (event->card && event->card->view)
manas.push_back(NEW ManaIcon(event->color, event->card->view->actX, event->card->view->actY));
else
manas.push_back(NEW ManaIcon(event->color, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
manas.push_back(NEW ManaIcon(event->color, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
return 1;
}
else return 0;
@@ -162,10 +162,10 @@ int GuiMana::receiveEventMinus(WEvent* e)
if ((event->color == (*it)->color) && (ManaIcon::ALIVE == (*it)->mode)) { (*it)->Wither(); return 1; }
return 1;
}
else if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
else if (WEventEmptyManaPool *event = dynamic_cast<WEventEmptyManaPool*>(e))
{
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
(*it)->Drop();
(*it)->Drop(); //TODO: split according to which manapool was emptied...
return 1;
}
return 0;

View File

@@ -1823,7 +1823,8 @@ int MTGAbility::removeFromGame(){
int MTGAbility::testDestroy(){
if (game->mLayers->stackLayer()->has(this)) return 0;
if (waitingForAnswer) return 0;
if (forceDestroy) return 1;
if (forceDestroy == 1) return 1;
if (forceDestroy == -1) return 0;
if (!game->isInPlay(source) ){
OutputDebugString("Destroying Ability !!!\n");
return 1;
@@ -2292,74 +2293,14 @@ AManaProducer::AManaProducer(int id, MTGCardInstance * card, ManaCost * _output,
aType = MTGAbility::MANA_PRODUCER;
cost = _cost;
output = _output;
cout << "!" << card->view << endl;
if (card->view)
{
x1 = card->view->actX; y1 = card->view->actY;
}
else
{
x1 = 10; y1 = 220;
}
Player * player = card->controller();
if (player == game->players[1]) y1 = 100;
x = x1;
y = y1;
animation = 0.f;
mParticleSys = NULL;
menutext = "";
int landColor = output->getMainColor();
switch (landColor)
{
case Constants::MTG_COLOR_RED :
mParticleSys = NEW hgeParticleSystem("graphics/manared.psi",GameApp::CommonRes->GetQuad("particles"));
break;
case Constants::MTG_COLOR_BLUE :
mParticleSys = NEW hgeParticleSystem("graphics/manablue.psi", GameApp::CommonRes->GetQuad("particles"));
break;
case Constants::MTG_COLOR_GREEN :
mParticleSys = NEW hgeParticleSystem("graphics/managreen.psi", GameApp::CommonRes->GetQuad("particles"));
break;
case Constants::MTG_COLOR_BLACK :
mParticleSys = NEW hgeParticleSystem("graphics/manablack.psi", GameApp::CommonRes->GetQuad("particles"));
break;
case Constants::MTG_COLOR_WHITE :
mParticleSys = NEW hgeParticleSystem("graphics/manawhite.psi", GameApp::CommonRes->GetQuad("particles"));
break;
default :
mParticleSys = NEW hgeParticleSystem("graphics/mana.psi", GameApp::CommonRes->GetQuad("particles"));
}
LOG("==ManaProducer Object Creation successful !");
}
void AManaProducer::Update(float dt){
if (mParticleSys) mParticleSys->Update(dt);
if (animation){
x = (1.f - animation)*x1 + animation * x0;
y = (1.f - animation)*y1 + animation * y0;
if (mParticleSys) mParticleSys->MoveTo(x, y);
if (mParticleSys && animation == 1.f) mParticleSys->Fire();
animation -= 4 *dt;
if (!animation) animation = -1;
if (animation < 0){
resolve();
}
}
}
void AManaProducer::Render(){
JRenderer * renderer = JRenderer::GetInstance();
if (animation){
// renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
// if (mParticleSys) mParticleSys->Render();
// set normal blending
// renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
}
}
int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana){
int result = 0;
if (!mana) mana = game->currentlyActing()->getManaPool();
@@ -2370,11 +2311,8 @@ void AManaProducer::Render(){
}
int AManaProducer::resolve(){
animation = 0;
if (currentlyTapping > 0) currentlyTapping--;
controller = source->controller();
controller->getManaPool()->add(output);
if (mParticleSys) mParticleSys->Stop();
controller->getManaPool()->add(output,source);
return 1;
}
@@ -2394,31 +2332,14 @@ void AManaProducer::Render(){
cost->doPayExtra();
}
if (tap) source->tap();
currentlyTapping++;
animation = 1.f;
if (options[Options::SFXVOLUME].number > 0 && currentlyTapping < 3){
if (options[Options::SFXVOLUME].number > 0){
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/mana.wav");
if (sample) JSoundSystem::GetInstance()->PlaySample(sample);
}
for (int i = Constants::MTG_NB_COLORS - 2; i >= 1; --i)
{
for (int cost = output->getCost(i); cost > 0; --cost)
{
WEvent * e = NEW WEventEngageMana(i, source);
GameObserver::GetInstance()->receiveEvent(e);
}
}
return 1;
return resolve();
}
int AManaProducer::destroy(){
if (animation >0) resolve(); //if we get destroyed while the animation was taking place (dirty...)
return MTGAbility::destroy();
}
const char * AManaProducer::getMenuText(){
if (menutext.size())return menutext.c_str();
@@ -2457,17 +2378,12 @@ void AManaProducer::Render(){
return menutext.c_str();
}
int AManaProducer::testDestroy(){
if (animation >0) return 0;
return MTGAbility::testDestroy();
}
AManaProducer::~AManaProducer(){
if (isClone) return;
LOG("==Destroying ManaProducer Object");
SAFE_DELETE(cost);
SAFE_DELETE(output);
SAFE_DELETE(mParticleSys);
LOG("==Destroying ManaProducer Object Successful!");
}
@@ -2477,19 +2393,4 @@ void AManaProducer::Render(){
return a;
}
int AManaProducer::currentlyTapping = 0;
ostream& AManaProducer::toString(ostream& out) const
{
out << "AManaProducer ::: cost : " << cost
<< " ; output : " << output
<< " ; menutext : " << menutext
<< " ; x0,y0 : " << x0 << "," << y0
<< " ; x1,y1 : " << x1 << "," << y1
<< " ; x,y : " << x << "," << y
<< " ; animation : " << animation
<< " ; controller : " << controller
<< " ; tap : " << tap
<< " (";
return MTGAbility::toString(out) << ")";
}

View File

@@ -15,7 +15,7 @@ void MTGGamePhase::Update(float dt){
int newState = GameObserver::GetInstance()->getCurrentGamePhase();
if (newState != currentState){
activeState = ACTIVE;
animation = 1;
animation = 4;
currentState = newState;
switch (currentState){
@@ -28,7 +28,7 @@ void MTGGamePhase::Update(float dt){
if (animation > 0){
// fprintf(stderr, "animation = %f", animation);
animation -= dt *5 ;
animation -- ;
}else{
activeState = INACTIVE;
animation = 0;

View File

@@ -1,10 +1,11 @@
#include "../include/config.h"
#include "../include/Logger.h"
#include "../include/ManaCost.h"
#include "../include/ManaCostHybrid.h"
#include "../include/ExtraCost.h"
#include "../include/TargetChooser.h"
#include "../include/Targetable.h"
#include "../include/Player.h"
#include "../include/WEvent.h"
#if defined (WIN32)
@@ -121,7 +122,6 @@ ManaCost::ManaCost(ManaCost * _manaCost){
}
ManaCost::~ManaCost(){
LOG("==Deleting ManaCost==");
for (unsigned int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
@@ -396,3 +396,58 @@ ostream& operator<<(ostream& out, const ManaCost& m)
{
return out << "(manacost)";
}
void ManaPool::init(){
ManaCost::init();
WEvent * e = NEW WEventEmptyManaPool(this);
GameObserver::GetInstance()->receiveEvent(e);
}
ManaPool::ManaPool(Player * player):ManaCost(),player(player){}
ManaPool::ManaPool(ManaCost * _manaCost,Player * player):ManaCost(_manaCost),player(player){}
int ManaPool::remove (int color, int value){
int result = ManaCost::remove(color, value);
for (int i = 0; i < value; ++i){
WEvent * e = NEW WEventConsumeMana(color, this);
GameObserver::GetInstance()->receiveEvent(e);
}
return result;
}
int ManaPool::add(int color, int value, MTGCardInstance * source ){
int result = ManaCost::add(color, value);
for (int i = 0; i < value; ++i){
WEvent * e = NEW WEventEngageMana(color, source,this);
GameObserver::GetInstance()->receiveEvent(e);
}
return result;
}
int ManaPool::add(ManaCost * _cost, MTGCardInstance * source){
if(!_cost) return 0;
int result = ManaCost::add(_cost);
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
for (int j = 0; j < _cost->getCost(i); j++){
WEvent * e = NEW WEventEngageMana(i, source, this);
GameObserver::GetInstance()->receiveEvent(e);
}
}
return result;
}
int ManaPool::pay (ManaCost * _cost){
int current[Constants::MTG_NB_COLORS];
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
current[i] = cost[i];
}
int result = ManaCost::pay(_cost);
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
int value = current[i] - cost[i];
for (int j = 0; j <value; j++){
WEvent * e = NEW WEventConsumeMana(i, this);
GameObserver::GetInstance()->receiveEvent(e);
}
}
return result;
}

View File

@@ -2,6 +2,7 @@
#include "../include/Player.h"
#include "../include/GameObserver.h"
#include "../include/DeckStats.h"
#include "../include/ManaCost.h"
Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageable(20){
@@ -9,7 +10,7 @@ Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageabl
deckFileSmall = fileSmall;
game = deck;
game->setOwner(this);
manaPool = NEW ManaCost();
manaPool = NEW ManaPool(this);
canPutLandsIntoPlay = 1;
mAvatar = NULL;
type_as_damageable = DAMAGEABLE_PLAYER;
@@ -21,9 +22,9 @@ void Player::End(){
}
Player::~Player(){
if (manaPool) delete manaPool;
if (mAvatarTex) delete mAvatarTex;
if (mAvatar) delete mAvatar;
SAFE_DELETE(manaPool);
SAFE_DELETE(mAvatarTex);
SAFE_DELETE(mAvatar);
}
const string Player::getDisplayName(){
@@ -63,7 +64,7 @@ HumanPlayer::HumanPlayer(MTGPlayerCards * deck, string file, string fileSmall) :
mAvatar = NEW JQuad(mAvatarTex, 0, 0, 35, 50);
}
ManaCost * Player::getManaPool(){
ManaPool * Player::getManaPool(){
return manaPool;
}

View File

@@ -66,7 +66,7 @@ int TestSuiteAI::Act(float dt){
timer+= dt;
if (AManaProducer::currentlyTapping || timer < suite->timerLimit) return 1;
if (timer < suite->timerLimit) return 1;
timer = 0;
string action = suite->getNextAction();

View File

@@ -22,5 +22,6 @@ WEventCreatureBlocker::WEventCreatureBlocker(MTGCardInstance * card, MTGCardInst
WEventCreatureBlockerRank::WEventCreatureBlockerRank(MTGCardInstance * card, MTGCardInstance * exchangeWith, MTGCardInstance * attacker) : WEventCardUpdate(card), exchangeWith(exchangeWith), attacker(attacker){}
WEventEngageMana::WEventEngageMana(int color, MTGCardInstance* card) : WEvent(), color(color), card(card) {}
WEventConsumeMana::WEventConsumeMana(int color) : WEvent(), color(color) {}
WEventEngageMana::WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination) : WEvent(), color(color), card(card), destination(destination) {}
WEventConsumeMana::WEventConsumeMana(int color, ManaPool * source) : WEvent(), color(color),source(source) {}
WEventEmptyManaPool::WEventEmptyManaPool(ManaPool * source):WEvent(),source(source){}