Skip to content

Commit

Permalink
"2.11: RM2000: Skill animations on ally only plays sound
Browse files Browse the repository at this point in the history
  • Loading branch information
Albeleon authored and mateofio committed Nov 18, 2018
1 parent 9062472 commit 423f5cb
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 27 deletions.
24 changes: 18 additions & 6 deletions src/battle_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "player.h"
#include "game_temp.h"

BattleAnimation::BattleAnimation(const RPG::Animation& anim) :
animation(anim), frame(0), frame_update(false)
BattleAnimation::BattleAnimation(const RPG::Animation& anim, bool only_sound) :
animation(anim), frame(0), frame_update(false), should_only_sound(only_sound)
{
SetZ(Priority_BattleAnimation);

Expand Down Expand Up @@ -139,6 +139,10 @@ void BattleAnimation::DrawAt(int x, int y) {
}
}

bool BattleAnimation::ShouldOnlySound() const {
return should_only_sound;
}

// FIXME: looks okay, but needs to be measured
static int flash_length = 12;

Expand All @@ -155,6 +159,8 @@ void BattleAnimation::RunTimedSfx() {
void BattleAnimation::ProcessAnimationTiming(const RPG::AnimationTiming& timing) {
// Play the SE.
Game_System::SePlay(timing.se);
if (ShouldOnlySound())
return;

// Flash.
if (timing.flash_scope == RPG::AnimationTiming::FlashScope_target) {
Expand Down Expand Up @@ -214,6 +220,8 @@ BattleAnimationChara::~BattleAnimationChara() {
Graphics::RemoveDrawable(this);
}
void BattleAnimationChara::Draw() {
if (ShouldOnlySound())
return;
//If animation is targeted on the screen
if (animation.scope == RPG::Animation::Scope_screen) {
DrawAt(SCREEN_TARGET_WIDTH / 2, SCREEN_TARGET_HEIGHT / 2);
Expand All @@ -231,20 +239,22 @@ bool BattleAnimationChara::ShouldScreenFlash() const { return true; }

/////////

BattleAnimationBattlers::BattleAnimationBattlers(const RPG::Animation& anim, Game_Battler& batt, bool flash) :
BattleAnimation(anim), battlers(std::vector<Game_Battler*>(1, &batt)), should_flash(flash)
BattleAnimationBattlers::BattleAnimationBattlers(const RPG::Animation& anim, Game_Battler& batt, bool flash, bool only_sound) :
BattleAnimation(anim, only_sound), battlers(std::vector<Game_Battler*>(1, &batt)), should_flash(flash)
{
Graphics::RegisterDrawable(this);
}
BattleAnimationBattlers::BattleAnimationBattlers(const RPG::Animation& anim, const std::vector<Game_Battler*>& batts, bool flash) :
BattleAnimation(anim), battlers(batts), should_flash(flash)
BattleAnimationBattlers::BattleAnimationBattlers(const RPG::Animation& anim, const std::vector<Game_Battler*>& batts, bool flash, bool only_sound) :
BattleAnimation(anim, only_sound), battlers(batts), should_flash(flash)
{
Graphics::RegisterDrawable(this);
}
BattleAnimationBattlers::~BattleAnimationBattlers() {
Graphics::RemoveDrawable(this);
}
void BattleAnimationBattlers::Draw() {
if (ShouldOnlySound())
return;
if (animation.scope == RPG::Animation::Scope_screen) {
DrawAt(SCREEN_TARGET_WIDTH / 2, SCREEN_TARGET_HEIGHT / 3);
return;
Expand Down Expand Up @@ -282,6 +292,8 @@ BattleAnimationGlobal::~BattleAnimationGlobal() {
Graphics::RemoveDrawable(this);
}
void BattleAnimationGlobal::Draw() {
if (ShouldOnlySound())
return;
// The animations are played at the vertices of a regular grid,
// 20 tiles wide by 10 tiles high, independant of the map.
// NOTE: not accurate, but see #574
Expand Down
8 changes: 5 additions & 3 deletions src/battle_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct FileRequestResult;

class BattleAnimation : public Sprite {
public:
BattleAnimation(const RPG::Animation& anim);
BattleAnimation(const RPG::Animation& anim, bool only_sound = false);

DrawableType GetType() const override;

Expand All @@ -47,12 +47,14 @@ class BattleAnimation : public Sprite {
protected:
virtual void SetFlash(Color c) = 0;
virtual bool ShouldScreenFlash() const = 0;
bool ShouldOnlySound() const;
void DrawAt(int x, int y);
void RunTimedSfx();
void ProcessAnimationTiming(const RPG::AnimationTiming& timing);
void OnBattleSpriteReady(FileRequestResult* result);
void OnBattle2SpriteReady(FileRequestResult* result);

bool should_only_sound;
const RPG::Animation& animation;
int frame;
bool frame_update;
Expand All @@ -75,8 +77,8 @@ class BattleAnimationChara : public BattleAnimation {
// For playing animations against a (group of) battlers in battle.
class BattleAnimationBattlers : public BattleAnimation {
public:
BattleAnimationBattlers(const RPG::Animation& anim, Game_Battler& batt, bool flash = true);
BattleAnimationBattlers(const RPG::Animation& anim, const std::vector<Game_Battler*>& batts, bool flash = true);
BattleAnimationBattlers(const RPG::Animation& anim, Game_Battler& batt, bool flash = true, bool only_sound = false);
BattleAnimationBattlers(const RPG::Animation& anim, const std::vector<Game_Battler*>& batts, bool flash = true, bool only_sound = false);
~BattleAnimationBattlers() override;
void Draw() override;
protected:
Expand Down
8 changes: 4 additions & 4 deletions src/game_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Spriteset_Battle& Game_Battle::GetSpriteset() {
return *spriteset;
}

void Game_Battle::ShowBattleAnimation(int animation_id, Game_Battler* target, bool flash) {
void Game_Battle::ShowBattleAnimation(int animation_id, Game_Battler* target, bool flash, bool only_sound) {
Main_Data::game_data.screen.battleanim_id = animation_id;

const RPG::Animation* anim = ReaderUtil::GetElement(Data::animations, animation_id);
Expand All @@ -188,10 +188,10 @@ void Game_Battle::ShowBattleAnimation(int animation_id, Game_Battler* target, bo
return;
}

animation.reset(new BattleAnimationBattlers(*anim, *target, flash));
animation.reset(new BattleAnimationBattlers(*anim, *target, flash, only_sound));
}

void Game_Battle::ShowBattleAnimation(int animation_id, const std::vector<Game_Battler*>& targets, bool flash) {
void Game_Battle::ShowBattleAnimation(int animation_id, const std::vector<Game_Battler*>& targets, bool flash, bool only_sound) {
Main_Data::game_data.screen.battleanim_id = animation_id;

const RPG::Animation* anim = ReaderUtil::GetElement(Data::animations, animation_id);
Expand All @@ -200,7 +200,7 @@ void Game_Battle::ShowBattleAnimation(int animation_id, const std::vector<Game_B
return;
}

animation.reset(new BattleAnimationBattlers(*anim, targets, flash));
animation.reset(new BattleAnimationBattlers(*anim, targets, flash, only_sound));
}

bool Game_Battle::IsBattleAnimationWaiting() {
Expand Down
4 changes: 2 additions & 2 deletions src/game_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Game_Battle {
* @param target pointer to the battler to play against
* @param flash whether or not the screen should flash during the animation
*/
void ShowBattleAnimation(int animation_id, Game_Battler* target, bool flash = true);
void ShowBattleAnimation(int animation_id, Game_Battler* target, bool flash = true, bool only_sound = false);

/**
* Plays a battle animation against several targets simultaneously.
Expand All @@ -78,7 +78,7 @@ namespace Game_Battle {
* @param targets a vector of pointer to the battlers to play against
* @param flash whether or not the screen should flash during the animation
*/
void ShowBattleAnimation(int animation_id, const std::vector<Game_Battler*>& targets, bool flash = true);
void ShowBattleAnimation(int animation_id, const std::vector<Game_Battler*>& targets, bool flash = true, bool only_sound = false);

/**
* Whether or not a battle animation is currently playing.
Expand Down
44 changes: 38 additions & 6 deletions src/game_battlealgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ void Game_BattleAlgorithm::AlgorithmBase::PlayAnimation(bool on_source) {
first_attack = old_first_attack;
}

void Game_BattleAlgorithm::AlgorithmBase::PlaySoundAnimation(bool on_source) {
if (current_target == targets.end() || !GetAnimation()) {
return;
}

if (on_source) {
std::vector<Game_Battler*> anim_targets = { GetSource() };
Game_Battle::ShowBattleAnimation(GetAnimation()->ID, anim_targets, false, true);
return;
}

auto old_current_target = current_target;
bool old_first_attack = first_attack;

std::vector<Game_Battler*> anim_targets;

do {
anim_targets.push_back(*current_target);
} while (TargetNextInternal());

Game_Battle::ShowBattleAnimation(
GetAnimation()->ID,
anim_targets, false, true);

current_target = old_current_target;
first_attack = old_first_attack;
}

bool Game_BattleAlgorithm::AlgorithmBase::IsSuccess() const {
return success;
}
Expand Down Expand Up @@ -737,6 +765,10 @@ bool Game_BattleAlgorithm::AlgorithmBase::IsReflected() const {
return false;
}

bool Game_BattleAlgorithm::AlgorithmBase::IsSoundAnimationOnAlly() const {
return false;
}

Game_BattleAlgorithm::Normal::Normal(Game_Battler* source, Game_Battler* target) :
AlgorithmBase(source, target) {
// no-op
Expand Down Expand Up @@ -1161,12 +1193,7 @@ const RPG::Sound* Game_BattleAlgorithm::Skill::GetStartSe() const {
return &skill.sound_effect;
}
else {
if (source->GetType() == Game_Battler::Type_Enemy) {
return &Game_System::GetSystemSE(Game_System::SFX_EnemyAttacks);
}
else {
return NULL;
}
return NULL;
}
}

Expand Down Expand Up @@ -1238,6 +1265,10 @@ bool Game_BattleAlgorithm::Skill::IsReflected() const {
return has_reflect;
}

bool Game_BattleAlgorithm::Skill::IsSoundAnimationOnAlly() const {
return true;
}

Game_BattleAlgorithm::Item::Item(Game_Battler* source, Game_Battler* target, const RPG::Item& item) :
AlgorithmBase(source, target), item(item) {
// no-op
Expand Down Expand Up @@ -1705,3 +1736,4 @@ bool Game_BattleAlgorithm::NoMove::Execute() {
void Game_BattleAlgorithm::NoMove::Apply() {
ApplyActionSwitches();
}

8 changes: 8 additions & 0 deletions src/game_battlealgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class AlgorithmBase {
*/
void PlayAnimation(bool on_source = false);

void PlaySoundAnimation(bool on_source = false);

/**
* Returns a list of all inflicted/removed conditions.
*
Expand Down Expand Up @@ -321,6 +323,11 @@ class AlgorithmBase {
*/
virtual bool IsReflected() const;

/**
* @return true if this action uses PlaySoundAnimation() on allies
*/
virtual bool IsSoundAnimationOnAlly() const;

protected:
AlgorithmBase(Game_Battler* source);
AlgorithmBase(Game_Battler* source, Game_Battler* target);
Expand Down Expand Up @@ -412,6 +419,7 @@ class Skill : public AlgorithmBase {
void GetResultMessages(std::vector<std::string>& out) const override;
int GetPhysicalDamageRate() const override;
bool IsReflected() const override;
bool IsSoundAnimationOnAlly() const override;

private:
const RPG::Skill& skill;
Expand Down
14 changes: 8 additions & 6 deletions src/scene_battle_rpg2k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,14 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
if (battle_message_window->GetLineCount() == 1 && action->HasSecondStartMessage()) {
return false;
}
if (action->GetTarget() &&
action->GetTarget()->GetType() == Game_Battler::Type_Enemy) {

action->PlayAnimation();
if (action->GetTarget()) {
if (action->GetTarget()->GetType() == Game_Battler::Type_Enemy) {
battle_action_wait = GetDelayForLine();
action->PlayAnimation();
} else if (action->GetTarget()->GetType() == Game_Battler::Type_Ally && action->IsSoundAnimationOnAlly()) {
battle_action_wait = GetDelayForLine();
action->PlaySoundAnimation();
}
}
}

Expand All @@ -463,8 +467,6 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase

battle_action_state = BattleActionState_Result;

battle_action_wait = GetDelayForWindow();

break;
case BattleActionState_ConditionHeal:
if (action->IsFirstAttack()) {
Expand Down

0 comments on commit 423f5cb

Please sign in to comment.