'die' animation is now managed for all actions.

This commit is contained in:
joris 2012-03-31 09:34:59 +02:00
parent f8c3d9e107
commit 5522c43686
9 changed files with 129 additions and 32 deletions

View file

@ -62,6 +62,7 @@ source_group(action FILES ${action_SRCS})
set(animation_SRCS
src/animation/animation.cpp
src/animation/animation_die.cpp
)
source_group(animation FILES ${animation_SRCS})
@ -374,6 +375,9 @@ set(stratagus_action_HDRS
src/include/action/action_upgradeto.h
)
set(stratagus_animation_HDRS
src/include/animation/animation_die.h
)
set(stratagus_generic_HDRS
src/ai/ai_local.h
@ -440,9 +444,10 @@ set(stratagus_generic_HDRS
source_group(include FILES ${stratagus_generic_HDRS})
source_group(include\\action FILES ${stratagus_action_HDRS})
source_group(include\\animation FILES ${stratagus_animation_HDRS})
source_group(include\\guichan FILES ${stratagus_guichan_HDRS})
set (stratagus_HDRS ${stratagus_generic_HDRS} ${stratagus_action_HDRS} ${stratagus_guichan_HDRS})
set (stratagus_HDRS ${stratagus_generic_HDRS} ${stratagus_action_HDRS} ${stratagus_animation_HDRS} ${stratagus_guichan_HDRS})
# Additional platform checks

View file

@ -379,12 +379,6 @@ bool AutoAttack(CUnit &unit)
if (unit.Anim.Unbreakable) { // animation can't be aborted here
return;
}
if (unit.CurrentOrder()->NeedToDie) { // we used the "die" action in animations
this->Finished = true;
unit.State = 0;
LetUnitDie(unit);
return;
}
this->State = SUB_STILL_STANDBY;
this->Finished = (this->Action == UnitActionStill);
if (this->Action == UnitActionStandGround || unit.Removed || unit.CanMove() == false) {

View file

@ -59,6 +59,7 @@
#include "action/action_unload.h"
#include "action/action_upgradeto.h"
#include "animation/animation_die.h"
#include "commands.h"
#include "map.h"
#include "missile.h"
@ -444,9 +445,11 @@ static void UnitActionsEachCycle(UNITP_ITERATOR begin, UNITP_ITERATOR end)
if (unit.Destroyed) {
continue;
}
HandleUnitAction(unit);
try {
HandleUnitAction(unit);
} catch (AnimationDie_Exception& ) {
AnimationDie_OnCatch(unit);
}
#ifdef DEBUG_LOG
DumpUnitInfo();
#endif

View file

@ -41,6 +41,7 @@
#include "actions.h"
#include "animation.h"
#include "animation/animation_die.h"
#include "script.h"
#include "map.h"
@ -758,22 +759,6 @@ static void AnimationSetPlayerVar_Action(CUnit &unit)
SetPlayerData(playerId, var, arg, rop);
}
static void AnimationDie_Action(CUnit &unit)
{
Assert(unit.Anim.Anim->Type == AnimationDie);
if (unit.Anim.Unbreakable) {
fprintf(stderr, "Can't call \"die\" action in unbreakable section\n");
Exit(1);
}
if (unit.Anim.Anim->D.Die.DeathType[0] != '\0') {
unit.DamagedType = ExtraDeathIndex(unit.Anim.Anim->D.Die.DeathType);
}
unit.CurrentOrder()->NeedToDie = true;
}
static void AnimationRotate_Action(CUnit &unit)
{
Assert(unit.Anim.Anim->Type == AnimationRotate);
@ -897,9 +882,6 @@ int UnitShowAnimationScaled(CUnit &unit, const CAnimation *anim, int scale)
int move = 0;
while (!unit.Anim.Wait) {
CAnimation::Action(unit, move, scale);
if (unit.Anim.Anim->Type == AnimationDie) {
return 0;
}
if (!unit.Anim.Wait) {
// Advance to next frame
unit.Anim.Anim = unit.Anim.Anim->Next;

View file

@ -0,0 +1,63 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name animation_die.cpp - The animation die. */
//
// (c) Copyright 1998-2005 by Lutz Sammer, Russell Smith, and Jimmy Salmon
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; only version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include "stratagus.h"
#include "animation/animation_die.h"
#include "animation.h"
#include "unit.h"
void AnimationDie_Action(CUnit &unit)
{
Assert(unit.Anim.Anim->Type == AnimationDie);
if (unit.Anim.Unbreakable) {
fprintf(stderr, "Can't call \"die\" action in unbreakable section\n");
Exit(1);
}
if (unit.Anim.Anim->D.Die.DeathType[0] != '\0') {
unit.DamagedType = ExtraDeathIndex(unit.Anim.Anim->D.Die.DeathType);
}
throw AnimationDie_Exception();
}
void AnimationDie_OnCatch(CUnit& unit)
{
unit.State = 0;
LetUnitDie(unit);
}
//@}

View file

@ -102,7 +102,7 @@ struct lua_State;
class COrder
{
public:
explicit COrder(int action) : Goal(NULL), Action(action), Finished(false), NeedToDie(false)
explicit COrder(int action) : Goal(NULL), Action(action), Finished(false)
{
}
virtual ~COrder();
@ -164,7 +164,6 @@ private:
public:
const unsigned char Action; /// global action
bool Finished; /// true when order is finish
bool NeedToDie;/// unit called a "die" animation and needs to die
};
/*----------------------------------------------------------------------------

View file

@ -35,6 +35,8 @@
#include <string>
#include <map>
#include "sound.h"
#define ANIMATIONS_MAXANIM 1024
#define ANIMATIONS_DEATHTYPES 40

View file

@ -0,0 +1,50 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name animation_die.h - The animation die headerfile. */
//
// (c) Copyright 2005-2007 by Jimmy Salmon
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; only version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
#ifndef __ANIMATION_DIE_H__
#define __ANIMATION_DIE_H__
//@{
class CUnit;
class AnimationDie_Exception
{
};
extern void AnimationDie_Action(CUnit &unit);
extern void AnimationDie_OnCatch(CUnit& unit);
//@}
#endif // !__ANIMATION_DIE_H__

View file

@ -2619,7 +2619,6 @@ PixelPos CUnit::GetMapPixelPosCenter() const
*/
void LetUnitDie(CUnit &unit)
{
unit.CurrentOrder()->NeedToDie = false;
unit.Variable[HP_INDEX].Value = std::min<int>(0,unit.Variable[HP_INDEX].Value);
unit.Moving = 0;
unit.TTL = 0;