Files
wagic/projects/mtg/src/DamagerDamaged.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

89 lines
2.6 KiB
C++

#include "../include/config.h"
#include "../include/DamagerDamaged.h"
/*
Temporary objects that store the damages dealt to/from creatures during the combat phase
*/
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) : TransientCardView(card, x, y), show(show), damageSelecter(damageSelecter) {}
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) : TransientCardView(card, ref), show(show), damageSelecter(damageSelecter) {}
DamagerDamaged::~DamagerDamaged(){}
int DamagerDamaged::sumDamages(){
int total = 0;
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
total += i->damage;
return total;
}
bool DamagerDamaged::hasLethalDamage(){
return (sumDamages() >= card->life);
}
void DamagerDamaged::addDamage(int damage, DamagerDamaged* source){
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
if (i->source == source->card){
i->damage += damage;
if (0 >= i->damage) damages.erase(i);
return;
}
if (0 < damage) damages.push_back(Damage(source->card, card, damage));
return;
}
int DamagerDamaged::removeDamagesFrom(DamagerDamaged* source){
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
if (i->source == source->card){
int damage = i->damage;
damages.erase(i);
return damage;
}
return 0;
}
void DamagerDamaged::clearDamage()
{
damages.clear();
}
void DamagerDamaged::Render(CombatStep mode)
{
TransientCardView::Render();
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
mFont->SetBase(0);
switch (mode)
{
case BLOCKERS :
case ORDER :
mFont->SetColor(ARGB(92,255,255,255));
break;
case FIRST_STRIKE :
case DAMAGE :
mFont->SetColor(ARGB(255, 255, 64, 0));
break;
}
char buf[6];
// if (currentPlayer != damageSelecter){
/* if (hasLethalDamage()){
mFont->DrawString("X",x,y);
}*/
sprintf(buf, "%i", sumDamages());
mFont->DrawString(buf, actX - 14 * actZ + 5, actY - 14 * actZ);
/*
}else{
mFont->SetColor(ARGB(255,0,0,255));
sprintf(buf, "%i", damageToDeal);
mFont->DrawString(buf,x+5, y+5);
}
mFont->SetColor(ARGB(255,255,255,255));
*/
}
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) : DamagerDamaged(card, x, y, show, damageSelecter) {}
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) : DamagerDamaged(card, ref, show, damageSelecter) {}