Files
wagic/projects/mtg/src/ExtraCost.cpp
T
wagic.jeck f220d2e9b9 Jeck - Cache and resource manager merged, streamlined.
This is pretty major, so there'll probably be something wrong with it... even though I did spend a few hours looking.
NOTES:
 * If you've Retrieved it, don't delete it--- Use resources.Release(Whatever). 
    Textures automatically release subordinate quads.
 * Most of the time, use resources.RetrieveQuad to grab a quad. Should handle everything for you.
    RetrieveQuad will load the required texture, if needed.
    Only managed resources have a resource name ("back", "simon", etc). 
    Managed resources can be retrieved with GetTexture/GetQuad/GetWhatever.
    Non managed quads lookup by position/dimensions, defaulting to the whole texture.
 * Use resources.RetrieveTexture only when you need to do something special to it. 
    Calling retrieve texture with RETRIEVE_MANAGE will permanently add a texture to the manager
    RETRIEVE_LOCK and RETRIEVE_VRAM will lock a texture. It will not leave the cache until
    Release(JTexture*) is called, or as a last resort during cache overflow.
 * Try to only store (as a class member) pointers to textures retrieved with RETRIEVE_MANAGE. 
    All others may become invalid, although locked textures do have a high degree of stability. It's
    pretty safe to store a locked texture if you're not going to load much between uses.

There's a lot going on here, so I might have missed something... but it runs through the test suite alright.

TODO: 
 * When called without any arguments, RetrieveQuad sometimes leaves a thin border around the image. 
    This can be bypassed by specifying a quad one or two pixels less than the image size. Why?
 * I've had a crash while runing the Demo mode, something to do with receiveEventMinus? 
    This hasn't exactly reproduced on a clean SVN copy, (being a hang, rather than a crash) so 
    I've probably done something to worsen the problem somehow? I'll look into it tomorrow.
 * Clean up lock/unlock system, memory usage. Streamline interface, consider phasing out calls using GetWhatever() format.
2009-09-03 09:28:16 +00:00

136 lines
2.8 KiB
C++

#include "../include/ExtraCost.h"
#include "../include/TargetChooser.h"
#include "../include/MTGCardInstance.h"
#include "../include/Translate.h"
#include <JGE.h>
ExtraCost::ExtraCost( TargetChooser *_tc):tc(_tc){
}
ExtraCost::~ExtraCost(){
SAFE_DELETE(tc);
}
int ExtraCost::setSource(MTGCardInstance * _source){
source=_source;
if (tc){ tc->source = _source; tc->targetter = _source;}
return 1;
}
SacrificeCost::SacrificeCost(TargetChooser *_tc):ExtraCost(_tc){
if (tc) tc->targetter = NULL; //Sacrificing is not targetting, protections do not apply
target = NULL;
}
int SacrificeCost::setSource(MTGCardInstance * card){
ExtraCost::setSource(card);
if (tc) tc->targetter = NULL; //Sacrificing is not targetting, protections do not apply
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);
target = NULL;
if (tc) tc->initTargets();
return 1;
}
return 0;
}
void SacrificeCost::Render(){
//TODO : real stuff
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
sprintf(buffer, _("sacrifice").c_str());
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
//
//Container
//
ExtraCosts::ExtraCosts(){
action = NULL;
source = NULL;
}
void ExtraCosts::Render(){
//TODO cool window and stuff...
for (size_t i = 0; i < costs.size(); i++){
costs[i]->Render();
}
}
int ExtraCosts::setAction(MTGAbility * _action, MTGCardInstance * _card){
action = _action;
source = _card;
for (size_t 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 (size_t i = 0; i < costs.size(); i++){
if (int result = costs[i]->setPayment(card)) return result;
}
return 0;
}
int ExtraCosts::isPaymentSet(){
for (size_t i = 0; i < costs.size(); i++){
if (!costs[i]->isPaymentSet()) return 0;
}
return 1;
}
int ExtraCosts::doPay(){
int result = 0;
for (size_t i = 0; i < costs.size(); i++){
result+=costs[i]->doPay();
}
return result;
}
ExtraCosts::~ExtraCosts(){
for (size_t i = 0; i < costs.size(); i++){
SAFE_DELETE(costs[i]);
}
}
void ExtraCosts::Dump(){
#ifdef WIN32
char buf[4096];
OutputDebugString("=====\nDumping ExtraCosts=====\n");
sprintf(buf, "NbElements : %i\n", costs.size());
OutputDebugString(buf);
#endif
}