- Added remove/add counters as a cost, patch by Salmelo, thanks man!. See primitives/mtg.txt -> Thallid to see how it works
- added test for i286 by salmelo
- added basic display for counters (this needs improvement) by salmelo
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-03-22 04:26:42 +00:00
parent 99db31fe9d
commit 22a35d2265
15 changed files with 334 additions and 20 deletions
+49 -1
View File
@@ -8,7 +8,7 @@
#include "../include/GameObserver.h"
#include <Vector2D.h>
#include <assert.h>
#include "../include/Counters.h"
const float CardGui::Width = 28.0;
const float CardGui::Height = 40.0;
@@ -113,6 +113,22 @@ void CardGui::Render()
mFont->SetScale(1);
}
if (card->counters->mCount > 0) {
unsigned c = -1;
for (int i = 0; i < card->counters->mCount; i++) {
if (card->counters->counters[i]->name != "") c = i; break;
}
if (c + 1) {
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
sprintf(buffer, "%i",card->counters->counters[0]->nb);
mFont->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
mFont->SetScale(actZ);
mFont->DrawString(buffer, actX - 10*actZ , actY -(12 * actZ));
mFont->SetScale(1);
}
}
if (tc && !tc->canTarget(card)) {
if (!shadow) shadow = resources.GetQuad("shadow");
shadow->SetColor(ARGB(200,255,255,255));
@@ -334,6 +350,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
void CardGui::alternateRenderBig(const Pos& pos){
alternateRender(card,pos);
renderCountersBig(pos);
}
void CardGui::RenderBig(MTGCard* card, const Pos& pos){
@@ -362,8 +379,39 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos){
alternateRender(card,pos);
}
void CardGui::renderCountersBig(const Pos& pos){
// Write Named Counters
if (card->counters) {
JLBFont * font = resources.GetJLBFont("magic");
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
font->SetScale(0.8 * pos.actZ);
std::vector<string> txt = card->formattedText();
unsigned i = txt.size() + 1;
Counter * c = NULL;
for (int t = 0; t < card->counters->mCount; t++, i++) {
if (c) {
c = card->counters->getNext(c);
}else{
c = card->counters->counters[0];
}
if (c->nb > 0) {
char buf[512];
if (c->name != "") {
std::string s = c->name;
s[0] = toupper(s[0]);
sprintf(buf,_("%s counters: %i").c_str(),s.c_str(),c->nb);
}else{
sprintf(buf,_("%i/%i counters: %i").c_str(),c->power,c->toughness,c->nb);
}
font->DrawString(buf, pos.actX + (22 - BigWidth / 2)*pos.actZ, pos.actY + (-BigHeight/2 + 80 + 11 * i)*pos.actZ);
}
}
}
}
void CardGui::RenderBig(const Pos& pos){
RenderBig(card,pos);
renderCountersBig(pos);
}
+107
View File
@@ -4,6 +4,7 @@
#include "../include/Translate.h"
#include "../include/config.h"
#include "../include/Player.h"
#include "../include/Counters.h"
#include <JGE.h>
ExtraCost::ExtraCost( TargetChooser *_tc):tc(_tc){
@@ -55,6 +56,11 @@ int SacrificeCost::isPaymentSet(){
return 0;
}
int SacrificeCost::canPay(){
//Sacrifice does not have any additional restrictions.
return 1;
}
int SacrificeCost::doPay(){
if(target){
target->controller()->game->putInGraveyard(target);
@@ -75,6 +81,100 @@ void SacrificeCost::Render(){
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
//Counter costs
CounterCost * CounterCost::clone() const{
CounterCost * ec = NEW CounterCost(*this);
if (tc) ec->tc = tc->clone();
if (counter) ec->counter = NEW Counter(counter->target, counter->name.c_str(),counter->power, counter->toughness);
return ec;
}
CounterCost::CounterCost(Counter * _counter,TargetChooser *_tc):ExtraCost(_tc) {
if (tc) tc->targetter = NULL;
target = NULL;
counter = _counter;
hasCounters = 0;
}
int CounterCost::setSource(MTGCardInstance * _source){
ExtraCost::setSource(_source);
if (tc) tc->targetter = NULL;
if (!tc) target = _source;
return 1;
}
int CounterCost::setPayment(MTGCardInstance *card){
if (tc) {
int result = tc->addTarget(card);
if (result) {
if (counter->nb >= 0) return 1; //add counters always possible
target = card;
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
if (targetCounter && targetCounter->nb >= - counter->nb) {
hasCounters = 1;
return result;
}
}
}
return 0;
}
int CounterCost::isPaymentSet(){
if (!target) return 0;
if (counter->nb >=0) return 1; //add counters always possible
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
if (targetCounter && targetCounter->nb >= - counter->nb) {
hasCounters = 1;
}
if (target && hasCounters) return 1;
return 0;
}
int CounterCost::canPay(){
// if target needs to be chosen, then move on.
if (tc) return 1;
if (counter->nb >=0) return 1; //add counters always possible
// otherwise, move on only if target has enough counters
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
if (targetCounter && targetCounter->nb >= - counter->nb) return 1;
return 0;
}
int CounterCost::doPay(){
if (!target) return 0;
if (counter->nb >=0) { //Add counters as a cost
for (int i = 0; i < counter->nb; i++) {
target->counters->addCounter(counter->name.c_str(),counter->power,counter->toughness);
}
return 1;
}
//remove counters as a cost
if (hasCounters) {
for (int i = 0; i < - counter->nb; i++) {
target->counters->removeCounter(counter->name.c_str(),counter->power,counter->toughness);
}
hasCounters = 0;
return 1;
}
return 0;
}
void CounterCost::Render(){
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
mFont->SetColor(ARGB(255,255,255,255));
char buffer[200];
sprintf(buffer, "%s", _("counters").c_str());
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
CounterCost::~CounterCost(){
SAFE_DELETE(counter);
}
//
//Container
//
@@ -129,6 +229,13 @@ int ExtraCosts::isPaymentSet(){
return 1;
}
int ExtraCosts::canPay(){
for (size_t i = 0; i < costs.size(); i++){
if (!costs[i]->canPay()) return 0;
}
return 1;
}
int ExtraCosts::doPay(){
int result = 0;
for (size_t i = 0; i < costs.size(); i++){
+11 -3
View File
@@ -702,17 +702,23 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
if (found != string::npos){
found+=8;
int nb = 1;
string name = "";
size_t end = s.find(")", found);
size_t separator = s.find(",", found);
if (separator != string::npos){
string nbstr = s.substr(separator+1,end-separator-1);
size_t separator2 = s.find(",", separator+1);
if (separator2 != string::npos) {
name = s.substr(separator2+1,end-separator2-1);
}
string nbstr = s.substr(separator+1,separator2-separator-1);
nb = atoi(nbstr.c_str());
end = separator;
}
string spt = s.substr(found,end-found);
int power, toughness;
if ( parsePowerToughness(spt,&power, &toughness)){
MTGAbility * a = NEW AACounter(id,card,target,power,toughness,nb);
MTGAbility * a = NEW AACounter(id,card,target,name.c_str(),power,toughness,nb);
a->oneShot = 1;
return a;
}
@@ -1742,17 +1748,19 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
if (card == source && source->controller()==player && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness()))){
if (!cost) return 1;
cost->setExtraCostsAction(this, card);
if (!mana) mana = player->getManaPool();
if (!mana->canAfford(cost)) return 0;
if (!cost->canPayExtra()) return 0;
return 1;
}
return 0;
}
int ActivatedAbility::reactToClick(MTGCardInstance * card){
// if (cost) cost->setExtraCostsAction(this, card);
if (!isReactingToClick(card)) return 0;
if (cost){
cost->setExtraCostsAction(this, card);
if (!cost->isExtraPaymentSet()){
game->waitForExtraPayment = cost->extraCosts;
return 0;
+48 -1
View File
@@ -6,6 +6,7 @@
#include "../include/Targetable.h"
#include "../include/Player.h"
#include "../include/WEvent.h"
#include "../include/MTGAbility.h"
#if defined (WIN32)
@@ -64,6 +65,46 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
tc = tcf.createTargetChooser(target,c);
}
manaCost->addExtraCost(NEW SacrificeCost(tc));
}else if (value[0] == 'c'){
//Counters
OutputDebugString("Counter\n");
size_t counter_start = value.find("(");
int nb = 1;
string name = "";
size_t counter_end = value.find(")", counter_start);
size_t end = value.find(")", counter_start);
size_t separator = value.find(",", counter_start);
size_t separator2 = string::npos;
if (separator != string::npos){
separator2 = value.find(",", separator+1);
if (separator2 != string::npos) {
name = value.substr(separator2+1,counter_end-separator2-1);
}
string nbstr = value.substr(separator+1,separator2-separator-1);
nb = atoi(nbstr.c_str());
counter_end = separator;
}
string spt = value.substr(counter_start+1,counter_end-counter_start-1);
int power, toughness;
Counter * counter = NULL;
AbilityFactory abf;
if ( abf.parsePowerToughness(spt,&power, &toughness)){
counter = NEW Counter(c,name.c_str(),power,toughness);
counter->nb = nb;
}
TargetChooserFactory tcf;
TargetChooser * tc = NULL;
size_t target_start = string::npos;
if (separator2 != string::npos) {
target_start = value.find(",",separator2+1);
}
size_t target_end = end;
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,c);
}
manaCost->addExtraCost(NEW CounterCost(counter,tc));
}else{
int intvalue = atoi(value.c_str());
int colors[2];
@@ -247,7 +288,7 @@ int ManaCost::addHybrid(int c1, int v1, int c2, int v2){
int ManaCost::addExtraCost(ExtraCost * _cost){
if (!extraCosts) extraCosts = NEW ExtraCosts();
extraCosts->costs.push_back(_cost);
OutputDebugString("Adding Sacrifice\n");
OutputDebugString("Adding Extra cost\n");
return 1;
}
@@ -258,6 +299,12 @@ int ManaCost::isExtraPaymentSet(){
return extraCosts->isPaymentSet();
}
int ManaCost::canPayExtra(){
if (!extraCosts) return 1;
OutputDebugString("Checking costs for payability\n");
return extraCosts->canPay();
}
int ManaCost::doPayExtra(){
if (!extraCosts) return 0;
return extraCosts->doPay(); //TODO reset ?