f220d2e9b9
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.
133 lines
3.4 KiB
C++
133 lines
3.4 KiB
C++
#include "../include/config.h"
|
|
#include "../include/Damage.h"
|
|
#include "../include/MTGCardInstance.h"
|
|
#include "../include/Counters.h"
|
|
#include "../include/WEvent.h"
|
|
#include "../include/Translate.h"
|
|
#include "../include/WResourceManager.h"
|
|
|
|
Damage::Damage(MTGCardInstance * source, Damageable * target) {
|
|
init(source, target, source->getPower());
|
|
}
|
|
|
|
Damage::Damage(MTGCardInstance * source, Damageable * target, int damage) {
|
|
init(source, target, damage);
|
|
}
|
|
|
|
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
|
|
target = _target;
|
|
source = _source;
|
|
|
|
|
|
if (_damage < 0) _damage = 0; //Negative damages cannot happen
|
|
damage = _damage;
|
|
mHeight = 40;
|
|
type = ACTION_DAMAGE;
|
|
}
|
|
|
|
int Damage::resolve(){
|
|
if (damage <0) damage = 0; //Negative damages cannot happen
|
|
state = RESOLVED_OK;
|
|
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
|
|
MTGCardInstance * _target = (MTGCardInstance *)target;
|
|
if ((_target)->protectedAgainst(source)) damage = 0;
|
|
// Damage for WITHER on creatures
|
|
|
|
if (!damage){
|
|
state = RESOLVED_NOK;
|
|
return 0;
|
|
}
|
|
if (source->has(Constants::WITHER)){
|
|
for (int i = 0; i < damage; i++){
|
|
_target->counters->addCounter(-1, -1);
|
|
}
|
|
return 1;
|
|
}
|
|
_target->doDamageTest = 1;
|
|
}
|
|
|
|
GameObserver * g = GameObserver::GetInstance();
|
|
WEvent * e = NEW WEventDamage(this);
|
|
e = g->replacementEffects->replace(e);
|
|
|
|
int a = 0;
|
|
if (damage) a = target->dealDamage(damage);
|
|
|
|
//Send (Damage/Replaced effect) event to listeners
|
|
|
|
g->receiveEvent(e);
|
|
//SAFE_DELETE(e);
|
|
|
|
return a;
|
|
}
|
|
|
|
void Damage::Render(){
|
|
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
|
mFont->SetBase(0);
|
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
|
char buffer[200];
|
|
sprintf(buffer, _("Deals %i damage to").c_str(), damage);
|
|
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
|
|
JRenderer * renderer = JRenderer::GetInstance();
|
|
JQuad * quad = resources.RetrieveCard(source,CACHE_THUMB);
|
|
if (quad){
|
|
float scale = 30 / quad->mHeight;
|
|
renderer->RenderQuad(quad, x , y , 0,scale,scale);
|
|
}else{
|
|
mFont->DrawString(_(source->getName()).c_str(),x,y-15);
|
|
}
|
|
quad = target->getIcon();
|
|
if (quad){
|
|
float scale = 30 / quad->mHeight;
|
|
renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale);
|
|
}else{
|
|
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
|
mFont->DrawString(_(((MTGCardInstance *)target)->getName()).c_str(),x+120,y);
|
|
}
|
|
|
|
}
|
|
|
|
ostream& Damage::toString(ostream& out) const
|
|
{
|
|
out << "Damage ::: target : " << target << " ; damage " << damage;
|
|
return out;
|
|
}
|
|
|
|
DamageStack::DamageStack() {
|
|
currentState = -1;
|
|
type = ACTION_DAMAGES;
|
|
}
|
|
|
|
|
|
int DamageStack::resolve(){
|
|
for (int i = mCount-1; i>= 0; i--){
|
|
Damage * damage = (Damage*)mObjects[i];
|
|
if (damage->state == NOT_RESOLVED) damage->resolve();
|
|
//damage->resolve();
|
|
}
|
|
for (int i = mCount-1; i>= 0; i--){
|
|
Damage * damage = (Damage*)mObjects[i];
|
|
if (damage->state == RESOLVED_OK) damage->target->afterDamage();
|
|
//damage->target->afterDamage();
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void DamageStack::Render(){
|
|
int currenty = y;
|
|
for (int i= 0; i < mCount; i++){
|
|
Damage * damage = (Damage*)mObjects[i];
|
|
if (damage->state == NOT_RESOLVED){
|
|
damage->x = x;
|
|
damage->y = currenty;
|
|
currenty += damage->mHeight;
|
|
damage->Render();
|
|
}
|
|
}
|
|
}
|
|
|
|
ostream& DamageStack::toString(ostream& out) const
|
|
{
|
|
return (out << "DamageStack ::: currentState : " << currentState);
|
|
}
|