- Added Dr Solomat's TEMPEST expansion
- Added Sacrifice as part of the cost of activated abilities. Making it work as an extra cost for "put in play" still requires some work though. "Render" methods need to be written correctly
- Added cards with sacrifice in the existing sets. Most of them need testing...
This commit is contained in:
wagic.the.homebrew
2009-01-25 09:20:01 +00:00
parent f593d1289c
commit b6a17098a4
26 changed files with 2095 additions and 321 deletions
+28 -18
View File
@@ -274,6 +274,16 @@ ActionStack::ActionStack(int id, GameObserver* _game):GuiLayer(id, _game){
}
int ActionStack::has(MTGAbility * ability){
for (int i = 0; i < mCount ; i++){
if (((Interruptible *)mObjects[i])->type==ACTION_ABILITY){
StackAbility * action = ((StackAbility *)mObjects[i]);
if (action->state == NOT_RESOLVED && action->ability == ability) return 1;
}
}
return 0;
}
int ActionStack::has(Interruptible * action){
for (int i = 0; i < mCount ; i++){
if (mObjects[i] == action) return 1;
@@ -658,15 +668,15 @@ void ActionStack::Render(){
for (int i=0;i<mCount ;i++){
Interruptible * current = (Interruptible *)mObjects[i];
if (current && current->state==NOT_RESOLVED){
current->x = x0 + 5;
if (i != mCount -1){
current->y = currenty;
currenty += current->mHeight;
}else{
current->y = currenty + 40 ;
currenty += current->mHeight + 40;
}
current->Render();
current->x = x0 + 5;
if (i != mCount -1){
current->y = currenty;
currenty += current->mHeight;
}else{
current->y = currenty + 40 ;
currenty += current->mHeight + 40;
}
current->Render();
}
}
@@ -698,15 +708,15 @@ void ActionStack::Render(){
for (int i=0;i<mCount ;i++){
Interruptible * current = (Interruptible *)mObjects[i];
if (mObjects[i]!=NULL && current->display){
((Interruptible *)mObjects[i])->x = x0 + 5;
if (i != mCount -1){
((Interruptible *)mObjects[i])->y = currenty;
currenty += ((Interruptible *)mObjects[i])->mHeight;
}else{
((Interruptible *)mObjects[i])->y = currenty + 40 ;
currenty += ((Interruptible *)mObjects[i])->mHeight + 40;
}
mObjects[i]->Render();
((Interruptible *)mObjects[i])->x = x0 + 5;
if (i != mCount -1){
((Interruptible *)mObjects[i])->y = currenty;
currenty += ((Interruptible *)mObjects[i])->mHeight;
}else{
((Interruptible *)mObjects[i])->y = currenty + 40 ;
currenty += ((Interruptible *)mObjects[i])->mHeight + 40;
}
mObjects[i]->Render();
}
}
}
+118
View File
@@ -0,0 +1,118 @@
#include "../include/ExtraCost.h"
#include "../include/TargetChooser.h"
#include "../include/MTGCardInstance.h"
#include <JGE.h>
ExtraCost::ExtraCost( TargetChooser *_tc):tc(_tc){
}
int ExtraCost::setSource(MTGCardInstance * _source){
source=_source;
if (tc){ tc->source = _source;}
return 1;
}
SacrificeCost::SacrificeCost(TargetChooser *_tc):ExtraCost(_tc){
target = NULL;
if (!tc) OutputDebugString("Self Sacrifice\n");
}
int SacrificeCost::setSource(MTGCardInstance * card){
ExtraCost::setSource(card);
if (!tc) target = card;
return 1;
}
int SacrificeCost::setPayment(MTGCardInstance * card){
if (tc) {
int result = tc->addTarget(card);
if (result) {
target = card;
return result;
}
}
return 0;
}
int SacrificeCost::isPaymentSet(){
if (target) return 1;
return 0;
}
int SacrificeCost::doPay(){
if(target){
target->controller()->game->putInGraveyard(target);
return 1;
}
return 0;
}
void SacrificeCost::Render(){
//TODO : real stuff
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
sprintf(buffer, "sacrifice");
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
//
//Container
//
ExtraCosts::ExtraCosts(){
action = NULL;
source = NULL;
}
void ExtraCosts::Render(){
//TODO cool window and stuff...
for (int i=0; i < costs.size(); i++){
costs[i]->Render();
}
}
int ExtraCosts::setAction(MTGAbility * _action, MTGCardInstance * _card){
action = _action;
source = _card;
for (int i=0; i < costs.size(); i++){
costs[i]->setSource(_card);
}
return 1;
}
int ExtraCosts::reset(){
action = NULL;
source = NULL;
//TODO set all payments to "unset"
return 1;
}
int ExtraCosts::tryToSetPayment(MTGCardInstance * card){
for (int i=0; i < costs.size(); i++){
if (int result = costs[i]->setPayment(card)) return result;
}
return 0;
}
int ExtraCosts::isPaymentSet(){
for (int i=0; i < costs.size(); i++){
if (!costs[i]->isPaymentSet()) return 0;
}
return 1;
}
int ExtraCosts::doPay(){
int result = 0;
for (int i=0; i < costs.size(); i++){
result+=costs[i]->doPay();
}
return result;
}
void ExtraCosts::Dump(){
char buf[4096];
OutputDebugString("=====\nDumping ExtraCosts=====\n");
sprintf(buf, "NbElements : %i\n", costs.size());
OutputDebugString(buf);
}
+25 -9
View File
@@ -6,6 +6,7 @@
#include "../include/CardGui.h"
#include "../include/Damage.h"
#include "../include/DamageResolverLayer.h"
#include "../include/ExtraCost.h"
#include <JRenderer.h>
@@ -46,6 +47,7 @@ GameObserver::GameObserver(Player * _players[], int _nb_players){
currentGamePhase = -1;
targetChooser = NULL;
cardWaitingForTargets = NULL;
waitForExtraPayment = NULL;
reaction = 0;
gameOver = NULL;
phaseRing = NEW PhaseRing(_players,_nb_players);
@@ -213,6 +215,9 @@ void GameObserver::Render(){
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()){
JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0));
}
if (waitForExtraPayment){
waitForExtraPayment->Render();
}
}
@@ -275,17 +280,17 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
int result;
if (card) {
if (card == cardWaitingForTargets){
LOG("attempt to close targetting");
int _result = targetChooser->ForceTargetListReady();
if (_result){
result = TARGET_OK_FULL;
}else{
LOG("attempt to close targetting");
int _result = targetChooser->ForceTargetListReady();
if (_result){
result = TARGET_OK_FULL;
}else{
LOG("...but we cant!\n");
result = targetChooser->targetsReadyCheck();
}
LOG("...but we cant!\n");
result = targetChooser->targetsReadyCheck();
}
}else{
result = targetChooser->toggleTarget(card);
result = targetChooser->toggleTarget(card);
}
}else{
result = targetChooser->toggleTarget(clickedPlayer);
@@ -297,6 +302,17 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
}
}
if (waitForExtraPayment){
if (card){
waitForExtraPayment->tryToSetPayment(card);
}
if (waitForExtraPayment->isPaymentSet()){
waitForExtraPayment->action->reactToClick(waitForExtraPayment->source);
waitForExtraPayment = NULL;
}
return;
}
if (card){
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
+5
View File
@@ -118,6 +118,11 @@ void GuiLayers::Update(float dt, Player * currentPlayer){
u32 key;
while ((key = JGE::GetInstance()->ReadButton()))
{
GameObserver * game = GameObserver::GetInstance();
if (game->waitForExtraPayment && key == PSP_CTRL_CROSS){
game->waitForExtraPayment = NULL;
continue;
}
for (i=0; i<nbitems; i++){
if (!isAI){
if (0 != key)
+34 -11
View File
@@ -151,7 +151,7 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
cost = ManaCost::parseManaCost(line.substr(0,delimiter+1));
}
OutputDebugString("Pqrsing cost\n");
if (cost && !cost->getConvertedCost()){
if (cost && cost->isNull()){
OutputDebugString("Cost is null\n");
SAFE_DELETE(cost);
}
@@ -1040,12 +1040,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
game->addObserver(NEW APestilence(_id, card));
break;
}
/*case 1173: //Plague Rats
{
game->addObserver(NEW APlagueRats(_id, card, "Plague Rats"));
break;
}
*/
case 1174: //Raise Dead
{
MTGPlayerCards * zones = game->currentlyActing()->game;
@@ -1621,7 +1616,9 @@ MTGAbility::~MTGAbility(){
//returns 1 if this ability needs to be removed from the list of active abilities
int MTGAbility::testDestroy(){
if (!game->isInPlay(source)){
if (game->mLayers->stackLayer()->has(this)) return 0;
if (!game->isInPlay(source) ){
OutputDebugString("Destroying Ability !!!\n");
return 1;
}
if (target && !game->isInPlay((MTGCardInstance *)target)){
@@ -1647,16 +1644,32 @@ ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _c
int ActivatedAbility::isReactingToClick(MTGCardInstance * card){
Player * player = game->currentPlayer;
if (!playerturnonly) player = game->currentlyActing();
if (card == source && (!cost || player->getManaPool()->canAfford(cost)) && source->controller()==player && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness())) && player==game->currentlyActing())
if (card == source && source->controller()==player && player==game->currentlyActing() && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness()))){
if (!cost) return 1;
if (!player->getManaPool()->canAfford(cost)) return 0;
return 1;
}
return 0;
}
int ActivatedAbility::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
OutputDebugString("React To click 1\n");
if (cost){
cost->setExtraCostsAction(this, card);
OutputDebugString("React To click 2\n");
if (!cost->isExtraPaymentSet()){
OutputDebugString("React To click 3\n");
game->waitForExtraPayment = cost->extraCosts;
return 0;
}
game->currentlyActing()->getManaPool()->pay(cost);
cost->doPayExtra();
}
if (needsTapping) source->tapped = 1;
if (cost) game->currentlyActing()->getManaPool()->pay(cost);
fireAbility();
return 1;
}
@@ -1664,7 +1677,17 @@ int ActivatedAbility::reactToClick(MTGCardInstance * card){
int ActivatedAbility::reactToTargetClick(Targetable * object){
if (!isReactingToTargetClick(object)) return 0;
if (needsTapping) source->tapped = 1;
if (cost) game->currentlyActing()->getManaPool()->pay(cost);
if (cost){
if (object->typeAsTarget() == TARGET_CARD) cost->setExtraCostsAction(this, (MTGCardInstance *) object);
OutputDebugString("React To click 2\n");
if (!cost->isExtraPaymentSet()){
OutputDebugString("React To click 3\n");
game->waitForExtraPayment = cost->extraCosts;
return 0;
}
game->currentlyActing()->getManaPool()->pay(cost);
cost->doPayExtra();
}
fireAbility();
return 1;
+15 -13
View File
@@ -6,8 +6,8 @@ MTGPutInPlayRule::MTGPutInPlayRule(int _id):MTGAbility(_id, NULL){
}
int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card){
Player * player = game->currentlyActing();
Player * currentPlayer = game->currentPlayer;
Player * player = game->currentlyActing();
Player * currentPlayer = game->currentPlayer;
LOG("CANPUTINPLAY- check if card belongs to current player\n");
if (!player->game->hand->hasCard(card)) return 0;
LOG("CANPUTINPLAY- check if card is land or can be played\n");
@@ -23,17 +23,7 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card){
ManaCost * cost = card->getManaCost();
if (playerMana->canAfford(cost)){
LOG("CANPUTINPLAY- ManaCost ok\n");
if (game->targetListIsSet(card)){
#ifdef LOG
LOG("CANPUTINPLAY- Targets chosen -> OK\n");
#endif
return 1;
}else{
#ifdef LOG
LOG("CANPUTINPLAY- Targets not chosen yet\n");
#endif
return 0;
}
return 1;
}
}
return 0;
@@ -42,8 +32,20 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card){
int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
Player * player = game->currentlyActing();
ManaCost * cost = card->getManaCost();
if (cost->isExtraPaymentSet()){
if (!game->targetListIsSet(card)){
LOG("CANPUTINPLAY- Targets not chosen yet\n");
return 0;
}
}else{
cost->setExtraCostsAction(this, card);
game->waitForExtraPayment = cost->extraCosts;
return 0;
}
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
player->getManaPool()->pay(card->getManaCost());
card->getManaCost()->doPayExtra();
ManaCost * spellCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
if (card->hasType("land")){
+57
View File
@@ -2,6 +2,9 @@
#include "../include/Logger.h"
#include "../include/ManaCost.h"
#include "../include/ManaCostHybrid.h"
#include "../include/ExtraCost.h"
#include "../include/TargetChooser.h"
#include "../include/Targetable.h"
#if defined (WIN32)
@@ -50,6 +53,19 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){
}else if (value == "x"){
manaCost->x();
}else if (value == "t"){
//Tap is handled outside of Manacost
}else if (value[0] == 's'){
//sacrifice
OutputDebugString("Sacrifice\n");
TargetChooserFactory tcf;
TargetChooser * tc = NULL;
int target_start = value.find("(");
int target_end = value.find(")");
if (target_start!=string::npos && target_end!=string::npos){
string target = value.substr(target_start+1, target_end-1 - target_start);
tc = tcf.createTargetChooser(target,NULL);
}
manaCost->addExtraCost(NEW SacrificeCost(tc));
}else{
int intvalue = atoi(value.c_str());
int colors[2];
@@ -128,6 +144,7 @@ void ManaCost::init(){
cost[i] = 0;
}
nbhybrids = 0;
extraCosts = NULL;
}
@@ -139,6 +156,11 @@ void ManaCost::copy(ManaCost * _manaCost){
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
}
nbhybrids = _manaCost->nbhybrids;
if (_manaCost->extraCosts){
//TODO Deep copy ?
extraCosts = _manaCost->extraCosts;
}
}
int ManaCost::getCost(int color){
@@ -165,6 +187,12 @@ int ManaCost::hasColor(int color){
return 0;
}
int ManaCost::isNull(){
if (getConvertedCost()) return 0;
if (extraCosts) return 0;
return 1;
}
int ManaCost::getConvertedCost(){
int result = 0;
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
@@ -210,6 +238,35 @@ int ManaCost::addHybrid(int c1, int v1, int c2, int v2){
return nbhybrids;
}
int ManaCost::addExtraCost(ExtraCost * _cost){
if (!extraCosts) extraCosts = NEW ExtraCosts();
extraCosts->costs.push_back(_cost);
OutputDebugString("Adding Sacrifice\n");
return 1;
}
int ManaCost::isExtraPaymentSet(){
if (!extraCosts) return 1;
OutputDebugString("Checking costs\n");
return extraCosts->isPaymentSet();
}
int ManaCost::resetExtraPayment(){
if (!extraCosts) return 1;
return extraCosts->reset();
}
int ManaCost::doPayExtra(){
if (!extraCosts) return 0;
return extraCosts->doPay(); //TODO reset ?
}
int ManaCost::setExtraCostsAction(MTGAbility * action, MTGCardInstance * card){
if (extraCosts) extraCosts->setAction(action, card);
return 1;
}
int ManaCost::pay(ManaCost * _cost){
ManaCost * diff = Diff(_cost);
for (int i=0; i < Constants::MTG_NB_COLORS; i++){