mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Wiped CDefEssential
This commit is contained in:
parent
6cd0dd9843
commit
3bbff27127
@ -29,12 +29,9 @@ static long long pow(long long a, int b)
|
||||
|
||||
CDefHandler::CDefHandler()
|
||||
{
|
||||
notFreeImgs = false;
|
||||
}
|
||||
CDefHandler::~CDefHandler()
|
||||
{
|
||||
if (notFreeImgs)
|
||||
return;
|
||||
for (auto & elem : ourImages)
|
||||
{
|
||||
if (elem.bitmap)
|
||||
@ -44,11 +41,6 @@ CDefHandler::~CDefHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
CDefEssential::~CDefEssential()
|
||||
{
|
||||
for(auto & elem : ourImages)
|
||||
SDL_FreeSurface(elem.bitmap);
|
||||
}
|
||||
|
||||
void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
|
||||
{
|
||||
@ -350,14 +342,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
|
||||
return ret;
|
||||
}
|
||||
|
||||
CDefEssential * CDefHandler::essentialize()
|
||||
{
|
||||
auto ret = new CDefEssential();
|
||||
ret->ourImages = ourImages;
|
||||
notFreeImgs = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
CDefHandler * CDefHandler::giveDef(const std::string & defName)
|
||||
{
|
||||
ResourceID resID(std::string("SPRITES/") + defName, EResType::ANIMATION);
|
||||
@ -369,12 +353,4 @@ CDefHandler * CDefHandler::giveDef(const std::string & defName)
|
||||
nh->openFromMemory(data.get(), defName);
|
||||
return nh;
|
||||
}
|
||||
CDefEssential * CDefHandler::giveDefEss(const std::string & defName)
|
||||
{
|
||||
CDefEssential * ret;
|
||||
CDefHandler * temp = giveDef(defName);
|
||||
ret = temp->essentialize();
|
||||
delete temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -66,12 +66,6 @@ struct SSpriteDef
|
||||
ui32 TopMargin;
|
||||
} PACKED_STRUCT;
|
||||
|
||||
class CDefEssential //DefHandler with images only
|
||||
{
|
||||
public:
|
||||
std::vector<Cimage> ourImages;
|
||||
~CDefEssential();
|
||||
};
|
||||
|
||||
class CDefHandler
|
||||
{
|
||||
@ -91,13 +85,10 @@ public:
|
||||
int width, height; //width and height
|
||||
std::string defName;
|
||||
std::vector<Cimage> ourImages;
|
||||
bool notFreeImgs;
|
||||
|
||||
CDefHandler();
|
||||
~CDefHandler();
|
||||
|
||||
CDefEssential * essentialize();
|
||||
|
||||
static CDefHandler * giveDef(const std::string & defName);
|
||||
static CDefEssential * giveDefEss(const std::string & defName);
|
||||
};
|
||||
|
@ -58,13 +58,13 @@ bool CBattleAnimation::isEarliest(bool perStackConcurrency)
|
||||
{
|
||||
int lowestMoveID = owner->animIDhelper + 5;
|
||||
CBattleStackAnimation * thAnim = dynamic_cast<CBattleStackAnimation *>(this);
|
||||
CSpellEffectAnimation * thSen = dynamic_cast<CSpellEffectAnimation *>(this);
|
||||
CEffectAnimation * thSen = dynamic_cast<CEffectAnimation *>(this);
|
||||
|
||||
for(auto & elem : owner->pendingAnims)
|
||||
{
|
||||
|
||||
CBattleStackAnimation * stAnim = dynamic_cast<CBattleStackAnimation *>(elem.first);
|
||||
CSpellEffectAnimation * sen = dynamic_cast<CSpellEffectAnimation *>(elem.first);
|
||||
CEffectAnimation * sen = dynamic_cast<CEffectAnimation *>(elem.first);
|
||||
if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID)
|
||||
continue;
|
||||
|
||||
@ -171,7 +171,7 @@ bool CDefenceAnimation::init()
|
||||
if(attAnim && attAnim->stack->ID != stack->ID)
|
||||
continue;
|
||||
|
||||
CSpellEffectAnimation * sen = dynamic_cast<CSpellEffectAnimation *>(elem.first);
|
||||
CEffectAnimation * sen = dynamic_cast<CEffectAnimation *>(elem.first);
|
||||
if (sen)
|
||||
continue;
|
||||
|
||||
@ -243,7 +243,7 @@ CCreatureAnim::EAnimType CDefenceAnimation::getMyAnimType()
|
||||
if(killed)
|
||||
return CCreatureAnim::DEATH;
|
||||
|
||||
if (vstd::contains(stack->state, EBattleStackState::DEFENDING_ANIM))
|
||||
if(vstd::contains(stack->state, EBattleStackState::DEFENDING_ANIM))
|
||||
return CCreatureAnim::DEFENCE;
|
||||
|
||||
return CCreatureAnim::HITTED;
|
||||
@ -270,10 +270,15 @@ void CDefenceAnimation::nextFrame()
|
||||
|
||||
void CDefenceAnimation::endAnim()
|
||||
{
|
||||
if (killed)
|
||||
if(killed)
|
||||
{
|
||||
myAnim->setType(CCreatureAnim::DEAD);
|
||||
}
|
||||
else
|
||||
{
|
||||
myAnim->setType(CCreatureAnim::HOLDING);
|
||||
}
|
||||
|
||||
|
||||
CBattleAnimation::endAnim();
|
||||
|
||||
@ -791,7 +796,7 @@ bool CShootingAnimation::init()
|
||||
Point animPos(destPos.x - 126 + img->width() / 2,
|
||||
destPos.y - 105 + img->height() / 2);
|
||||
|
||||
owner->addNewAnim( new CSpellEffectAnimation(owner, catapultDamage ? "SGEXPL.DEF" : "CSGRCK.DEF", animPos.x, animPos.y));
|
||||
owner->addNewAnim( new CEffectAnimation(owner, catapultDamage ? "SGEXPL.DEF" : "CSGRCK.DEF", animPos.x, animPos.y));
|
||||
}
|
||||
|
||||
auto & angles = shooterInfo->animation.missleFrameAngles;
|
||||
@ -872,35 +877,40 @@ void CShootingAnimation::endAnim()
|
||||
delete this;
|
||||
}
|
||||
|
||||
CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx, int _dy, bool _Vflip, bool _alignToBottom)
|
||||
:CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), x(-1), y(-1), dx(_dx), dy(_dy), Vflip(_Vflip), alignToBottom(_alignToBottom)
|
||||
CEffectAnimation::CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip, bool _alignToBottom)
|
||||
: CBattleAnimation(_owner),
|
||||
destTile(BattleHex::INVALID),
|
||||
customAnim(_customAnim),
|
||||
x(_x),
|
||||
y(_y),
|
||||
dx(_dx),
|
||||
dy(_dy),
|
||||
Vflip(_Vflip),
|
||||
alignToBottom(_alignToBottom)
|
||||
{
|
||||
logAnim->debug("Created spell anim for effect #%d", effect);
|
||||
logAnim->debug("Created effect animation %s", customAnim);
|
||||
}
|
||||
|
||||
CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip, bool _alignToBottom)
|
||||
:CBattleAnimation(_owner), effect(-1), destTile(BattleHex::INVALID), customAnim(_customAnim), x(_x), y(_y), dx(_dx), dy(_dy), Vflip(_Vflip), alignToBottom(_alignToBottom)
|
||||
CEffectAnimation::CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip, bool _alignToBottom)
|
||||
: CBattleAnimation(_owner),
|
||||
destTile(_destTile),
|
||||
customAnim(_customAnim),
|
||||
x(-1),
|
||||
y(-1),
|
||||
dx(0),
|
||||
dy(0),
|
||||
Vflip(_Vflip),
|
||||
alignToBottom(_alignToBottom)
|
||||
{
|
||||
logAnim->debug("Created spell anim for %s", customAnim);
|
||||
}
|
||||
|
||||
CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip, bool _alignToBottom)
|
||||
:CBattleAnimation(_owner), effect(-1), destTile(_destTile), customAnim(_customAnim), x(-1), y(-1), dx(0), dy(0), Vflip(_Vflip), alignToBottom(_alignToBottom)
|
||||
{
|
||||
logAnim->debug("Created spell anim for %s", customAnim);
|
||||
logAnim->debug("Created effect animation %s", customAnim);
|
||||
}
|
||||
|
||||
|
||||
bool CSpellEffectAnimation::init()
|
||||
bool CEffectAnimation::init()
|
||||
{
|
||||
if(!isEarliest(true))
|
||||
return false;
|
||||
|
||||
if(customAnim.empty() && effect != ui32(-1) && !graphics->battleACToDef[effect].empty())
|
||||
{
|
||||
customAnim = graphics->battleACToDef[effect][0];
|
||||
}
|
||||
|
||||
if(customAnim.empty())
|
||||
{
|
||||
endAnim();
|
||||
@ -990,7 +1000,7 @@ bool CSpellEffectAnimation::init()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSpellEffectAnimation::nextFrame()
|
||||
void CEffectAnimation::nextFrame()
|
||||
{
|
||||
//notice: there may be more than one effect in owner->battleEffects correcponding to this animation (ie. armageddon)
|
||||
for(auto & elem : owner->battleEffects)
|
||||
@ -1013,7 +1023,7 @@ void CSpellEffectAnimation::nextFrame()
|
||||
}
|
||||
}
|
||||
|
||||
void CSpellEffectAnimation::endAnim()
|
||||
void CEffectAnimation::endAnim()
|
||||
{
|
||||
CBattleAnimation::endAnim();
|
||||
|
||||
|
@ -213,11 +213,10 @@ public:
|
||||
virtual ~CShootingAnimation(){};
|
||||
};
|
||||
|
||||
/// This class manages a spell effect animation
|
||||
class CSpellEffectAnimation : public CBattleAnimation
|
||||
/// This class manages effect animation
|
||||
class CEffectAnimation : public CBattleAnimation
|
||||
{
|
||||
private:
|
||||
ui32 effect;
|
||||
BattleHex destTile;
|
||||
std::string customAnim;
|
||||
int x, y, dx, dy;
|
||||
@ -228,8 +227,7 @@ public:
|
||||
void nextFrame() override;
|
||||
void endAnim() override;
|
||||
|
||||
CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
||||
CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
||||
CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip = false, bool _alignToBottom = false);
|
||||
virtual ~CSpellEffectAnimation(){};
|
||||
CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
||||
CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip = false, bool _alignToBottom = false);
|
||||
virtual ~CEffectAnimation(){};
|
||||
};
|
||||
|
@ -1221,7 +1221,7 @@ void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca)
|
||||
{
|
||||
Point destPos = CClickableHex::getXYUnitAnim(attackInfo.destinationTile, nullptr, this) + Point(99, 120);
|
||||
|
||||
addNewAnim(new CSpellEffectAnimation(this, "SGEXPL.DEF", destPos.x, destPos.y));
|
||||
addNewAnim(new CEffectAnimation(this, "SGEXPL.DEF", destPos.x, destPos.y));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1309,20 +1309,23 @@ void CBattleInterface::spellCast(const BattleSpellCast *sc)
|
||||
|
||||
std::string animToDisplay = spell.animationInfo.selectProjectile(angle);
|
||||
|
||||
if (!animToDisplay.empty())
|
||||
if(!animToDisplay.empty())
|
||||
{
|
||||
//TODO: calculate inside CEffectAnimation
|
||||
std::shared_ptr<CAnimation> tmp = std::make_shared<CAnimation>(animToDisplay);
|
||||
tmp->load(0, 0);
|
||||
IImage * first = tmp->getImage(0, 0);
|
||||
|
||||
//displaying animation
|
||||
CDefEssential *animDef = CDefHandler::giveDefEss(animToDisplay);
|
||||
double diffX = (destcoord.x - srccoord.x)*(destcoord.x - srccoord.x);
|
||||
double diffY = (destcoord.y - srccoord.y)*(destcoord.y - srccoord.y);
|
||||
double distance = sqrt(diffX + diffY);
|
||||
|
||||
int steps = distance / AnimationControls::getSpellEffectSpeed() + 1;
|
||||
int dx = (destcoord.x - srccoord.x - animDef->ourImages[0].bitmap->w)/steps;
|
||||
int dy = (destcoord.y - srccoord.y - animDef->ourImages[0].bitmap->h)/steps;
|
||||
int dx = (destcoord.x - srccoord.x - first->width())/steps;
|
||||
int dy = (destcoord.y - srccoord.y - first->height())/steps;
|
||||
|
||||
delete animDef;
|
||||
addNewAnim(new CSpellEffectAnimation(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip));
|
||||
addNewAnim(new CEffectAnimation(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip));
|
||||
}
|
||||
}
|
||||
waitForAnims();
|
||||
@ -1354,8 +1357,8 @@ void CBattleInterface::spellCast(const BattleSpellCast *sc)
|
||||
{
|
||||
Point leftHero = Point(15, 30) + pos;
|
||||
Point rightHero = Point(755, 30) + pos;
|
||||
addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false));
|
||||
addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false));
|
||||
addNewAnim(new CEffectAnimation(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false));
|
||||
addNewAnim(new CEffectAnimation(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1418,9 +1421,11 @@ void CBattleInterface::castThisSpell(SpellID spellID)
|
||||
}
|
||||
}
|
||||
|
||||
void CBattleInterface::displayEffect(ui32 effect, int destTile)
|
||||
void CBattleInterface::displayEffect(ui32 effect, BattleHex destTile)
|
||||
{
|
||||
addNewAnim(new CSpellEffectAnimation(this, effect, destTile, 0, 0, false));
|
||||
std::string customAnim = graphics->battleACToDef[effect][0];
|
||||
|
||||
addNewAnim(new CEffectAnimation(this, customAnim, destTile));
|
||||
}
|
||||
|
||||
void CBattleInterface::displaySpellAnimation(const CSpell::TAnimation & animation, BattleHex destinationTile)
|
||||
@ -1431,7 +1436,7 @@ void CBattleInterface::displaySpellAnimation(const CSpell::TAnimation & animatio
|
||||
}
|
||||
else
|
||||
{
|
||||
addNewAnim(new CSpellEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM));
|
||||
addNewAnim(new CEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2737,7 +2742,7 @@ void CBattleInterface::obstaclePlaced(const CObstacleInstance & oi)
|
||||
//we assume here that effect graphics have the same size as the usual obstacle image
|
||||
// -> if we know how to blit obstacle, let's blit the effect in the same place
|
||||
Point whereTo = getObstaclePosition(getObstacleImage(oi), oi);
|
||||
addNewAnim(new CSpellEffectAnimation(this, defname, whereTo.x, whereTo.y));
|
||||
addNewAnim(new CEffectAnimation(this, defname, whereTo.x, whereTo.y));
|
||||
|
||||
//TODO we need to wait after playing sound till it's finished, otherwise it overlaps and sounds really bad
|
||||
//CCS->soundh->playSound(sound);
|
||||
|
@ -120,6 +120,7 @@ class CBattleInterface : public CIntObject
|
||||
};
|
||||
private:
|
||||
SDL_Surface *background, *menu, *amountNormal, *amountNegative, *amountPositive, *amountEffNeutral, *cellBorders, *backgroundWithHexes;
|
||||
|
||||
CButton *bOptions, *bSurrender, *bFlee, *bAutofight, *bSpell,
|
||||
* bWait, *bDefence, *bConsoleUp, *bConsoleDown, *btactNext, *btactEnd;
|
||||
CBattleConsole *console;
|
||||
@ -342,7 +343,7 @@ public:
|
||||
void spellCast(const BattleSpellCast *sc); //called when a hero casts a spell
|
||||
void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks
|
||||
void castThisSpell(SpellID spellID); //called when player has chosen a spell from spellbook
|
||||
void displayEffect(ui32 effect, int destTile); //displays custom effect on the battlefield
|
||||
void displayEffect(ui32 effect, BattleHex destTile); //displays custom effect on the battlefield
|
||||
|
||||
void displaySpellCast(SpellID spellID, BattleHex destinationTile); //displays spell`s cast animation
|
||||
void displaySpellEffect(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation
|
||||
@ -378,7 +379,7 @@ public:
|
||||
|
||||
friend class CBattleResultWindow;
|
||||
friend class CBattleHero;
|
||||
friend class CSpellEffectAnimation;
|
||||
friend class CEffectAnimation;
|
||||
friend class CBattleStackAnimation;
|
||||
friend class CReverseAnimation;
|
||||
friend class CDefenceAnimation;
|
||||
|
@ -138,8 +138,9 @@ void CCreatureAnimation::setType(CCreatureAnim::EAnimType type)
|
||||
play();
|
||||
}
|
||||
|
||||
CCreatureAnimation::CCreatureAnimation(std::string name, TSpeedController controller)
|
||||
: speed(0.1),
|
||||
CCreatureAnimation::CCreatureAnimation(const std::string & name_, TSpeedController controller)
|
||||
: name(name_),
|
||||
speed(0.1),
|
||||
currentFrame(0),
|
||||
elapsedTime(0),
|
||||
type(CCreatureAnim::HOLDING),
|
||||
@ -147,8 +148,8 @@ CCreatureAnimation::CCreatureAnimation(std::string name, TSpeedController contro
|
||||
speedController(controller),
|
||||
once(false)
|
||||
{
|
||||
forward = std::make_shared<CAnimation>(name);
|
||||
reverse = std::make_shared<CAnimation>(name);
|
||||
forward = std::make_shared<CAnimation>(name_);
|
||||
reverse = std::make_shared<CAnimation>(name_);
|
||||
|
||||
//todo: optimize
|
||||
forward->preload();
|
||||
@ -269,8 +270,6 @@ void CCreatureAnimation::genBorderPalette(IImage::BorderPallete & target)
|
||||
target[2] = addColors(genShadow(64), genBorderColor(getBorderStrength(elapsedTime), border));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CCreatureAnimation::nextFrame(SDL_Surface *dest, bool attacker)
|
||||
{
|
||||
size_t frame = floor(currentFrame);
|
||||
@ -288,7 +287,6 @@ void CCreatureAnimation::nextFrame(SDL_Surface *dest, bool attacker)
|
||||
image->setBorderPallete(borderPallete);
|
||||
|
||||
image->draw(dest, pos.x, pos.y);
|
||||
|
||||
}
|
||||
|
||||
int CCreatureAnimation::framesInGroup(CCreatureAnim::EAnimType group) const
|
||||
@ -329,6 +327,7 @@ void CCreatureAnimation::pause()
|
||||
|
||||
void CCreatureAnimation::play()
|
||||
{
|
||||
logAnim->trace("Play %s group %d at %d:%d", name, static_cast<int>(getType()), pos.x, pos.y);
|
||||
speed = 0;
|
||||
if (speedController(this, type) != 0)
|
||||
speed = 1 / speedController(this, type);
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
typedef std::function<float(CCreatureAnimation *, size_t)> TSpeedController;
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::shared_ptr<CAnimation> forward;
|
||||
std::shared_ptr<CAnimation> reverse;
|
||||
|
||||
@ -92,7 +93,7 @@ public:
|
||||
/// name - path to .def file, relative to SPRITES/ directory
|
||||
/// controller - function that will return for how long *each* frame
|
||||
/// in specified group of animation should be played, measured in seconds
|
||||
CCreatureAnimation(std::string name, TSpeedController speedController);
|
||||
CCreatureAnimation(const std::string & name_, TSpeedController speedController);
|
||||
|
||||
void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
|
||||
CCreatureAnim::EAnimType getType() const; //returns type of animation
|
||||
|
@ -136,7 +136,7 @@ public:
|
||||
void verticalFlip();
|
||||
void playerColored(PlayerColor player);
|
||||
|
||||
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
|
||||
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
|
||||
};
|
||||
|
||||
const float DEFAULT_DELTA = 0.05f;
|
||||
|
@ -37,7 +37,6 @@ class CGObjectInstance;
|
||||
class CCreature;
|
||||
class CMap;
|
||||
struct StartInfo;
|
||||
struct SDL_Surface;
|
||||
class CMapHandler;
|
||||
struct SetObjectProperty;
|
||||
struct MetaString;
|
||||
|
Loading…
Reference in New Issue
Block a user