Skip to content

Commit

Permalink
Merge pull request #897 from Ghabry/development
Browse files Browse the repository at this point in the history
Fix bugs encountered (mostly in battles) in Ara Fell
  • Loading branch information
fdelapena committed May 29, 2016
2 parents d2c0f5c + 0a7d83f commit a16f258
Show file tree
Hide file tree
Showing 40 changed files with 2,417 additions and 1,914 deletions.
31 changes: 21 additions & 10 deletions src/battle_animation.cpp
Expand Up @@ -134,7 +134,12 @@ void BattleAnimation::OnBattle2SpriteReady(FileRequestResult* result) {

void BattleAnimation::DrawAt(int x, int y) {
if (!sprite) return; // Initialization failed
if (IsDone()) return;
if (IsDone()) {
return;
}
if (!sprite->GetVisible()) {
return;
}

const RPG::AnimationFrame& anim_frame = animation.frames[frame];

Expand All @@ -150,6 +155,7 @@ void BattleAnimation::DrawAt(int x, int y) {

sprite->SetX(cell.x + x);
sprite->SetY(cell.y + y);
sprite->SetZ(GetZ());
int sx = cell.cell_id % 5;
int sy = cell.cell_id / 5;
int size = large ? 128 : 96;
Expand All @@ -163,6 +169,11 @@ void BattleAnimation::DrawAt(int x, int y) {
sprite->SetOpacity(255 * (100 - cell.transparency) / 100);
sprite->SetZoomX(cell.zoom / 100.0);
sprite->SetZoomY(cell.zoom / 100.0);
}

if (anim_frame.cells.empty()) {
// Draw an empty sprite when no cell is available in the animation
sprite->SetSrcRect(Rect(0, 0, 0, 0));
sprite->Draw();
}
}
Expand All @@ -186,16 +197,16 @@ void BattleAnimation::ProcessAnimationTiming(const RPG::AnimationTiming& timing)

// Flash.
if (timing.flash_scope == RPG::AnimationTiming::FlashScope_target) {
Flash(Color(timing.flash_red << 3,
timing.flash_green << 3,
timing.flash_blue << 3,
timing.flash_power << 3));
Flash(Color(timing.flash_red,
timing.flash_green,
timing.flash_blue,
timing.flash_power));
} else if (timing.flash_scope == RPG::AnimationTiming::FlashScope_screen && ShouldScreenFlash()) {
Main_Data::game_screen->FlashOnce(
timing.flash_red << 3,
timing.flash_green << 3,
timing.flash_blue << 3,
timing.flash_power << 3,
timing.flash_red,
timing.flash_green,
timing.flash_blue,
timing.flash_power,
flash_duration);
}

Expand Down Expand Up @@ -259,7 +270,7 @@ void BattleAnimationBattlers::Draw() {
const Sprite_Battler* sprite = Game_Battle::GetSpriteset().FindBattler(&battler);
int offset = 0;
if (sprite && sprite->GetBitmap()) {
offset = CalculateOffset(animation.position, sprite->GetBitmap()->GetHeight());
offset = CalculateOffset(animation.position, sprite->GetHeight());
}
DrawAt(battler.GetBattleX(), battler.GetBattleY() + offset);
}
Expand Down
67 changes: 50 additions & 17 deletions src/game_actor.cpp
Expand Up @@ -238,9 +238,9 @@ int Game_Actor::GetSp() const {
}

int Game_Actor::GetBaseMaxHp(bool mod) const {
// The GetData().class_id check works around a save game corruption in old
// versions of the Player because GetData().changed_class was not set properly.
int n = GetData().changed_class && GetData().class_id > 0
// The .changed_class field is not reliable (and the purpose is unknown)
// because it is only true when the class was changed by an event
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.maxhp[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.maxhp[GetData().level - 1];

Expand All @@ -255,7 +255,7 @@ int Game_Actor::GetBaseMaxHp() const {
}

int Game_Actor::GetBaseMaxSp(bool mod) const {
int n = GetData().changed_class && GetData().class_id > 0
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.maxsp[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.maxsp[GetData().level - 1];

Expand All @@ -270,7 +270,7 @@ int Game_Actor::GetBaseMaxSp() const {
}

int Game_Actor::GetBaseAtk(bool mod, bool equip) const {
int n = GetData().changed_class && GetData().class_id > 0
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.attack[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.attack[GetData().level - 1];

Expand All @@ -294,7 +294,7 @@ int Game_Actor::GetBaseAtk() const {
}

int Game_Actor::GetBaseDef(bool mod, bool equip) const {
int n = GetData().changed_class && GetData().class_id > 0
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.defense[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.defense[GetData().level - 1];

Expand All @@ -318,7 +318,7 @@ int Game_Actor::GetBaseDef() const {
}

int Game_Actor::GetBaseSpi(bool mod, bool equip) const {
int n = GetData().changed_class && GetData().class_id > 0
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.spirit[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.spirit[GetData().level - 1];

Expand All @@ -342,7 +342,7 @@ int Game_Actor::GetBaseSpi() const {
}

int Game_Actor::GetBaseAgi(bool mod, bool equip) const {
int n = GetData().changed_class && GetData().class_id > 0
int n = GetData().class_id > 0
? Data::classes[GetData().class_id - 1].parameters.agility[GetData().level - 1]
: Data::actors[actor_id - 1].parameters.agility[GetData().level - 1];

Expand All @@ -368,7 +368,7 @@ int Game_Actor::GetBaseAgi() const {
int Game_Actor::CalculateExp(int level) const
{
double base, inflation, correction;
if (GetData().changed_class && GetData().class_id > 0) {
if (GetData().class_id > 0) {
const RPG::Class& klass = Data::classes[GetData().class_id - 1];
base = klass.exp_base;
inflation = klass.exp_inflation;
Expand Down Expand Up @@ -574,8 +574,13 @@ void Game_Actor::ChangeLevel(int new_level, bool level_up_message) {
if (level_up_message) {
std::stringstream ss;
ss << GetData().name << " ";
ss << Data::terms.level << " " << new_level;
ss << Data::terms.level_up;
if (Player::IsRPG2k3E()) {
ss << Data::terms.level_up << " ";
ss << Data::terms.level << " " << new_level;
} else {
ss << Data::terms.level << " " << new_level;
ss << Data::terms.level_up;
}
Game_Message::texts.push_back(ss.str());
level_up = true;
}
Expand All @@ -588,7 +593,7 @@ void Game_Actor::ChangeLevel(int new_level, bool level_up_message) {
if (LearnSkill(it->skill_id) && level_up_message) {
std::stringstream ss;
ss << Data::skills[it->skill_id - 1].name;
ss << Data::terms.skill_learned;
ss << (Player::IsRPG2k3E() ? " " : "") << Data::terms.skill_learned;
Game_Message::texts.push_back(ss.str());
level_up = true;
}
Expand Down Expand Up @@ -856,21 +861,30 @@ const std::vector<const RPG::BattleCommand*> Game_Actor::GetBattleCommands() con
return commands;
}

int Game_Actor::GetClass() const {
return GetData().class_id;
const RPG::Class* Game_Actor::GetClass() const {
if (GetData().class_id <= 0) {
return nullptr;
}

return &Data::classes[GetData().class_id - 1];
}

void Game_Actor::SetClass(int _class_id) {
GetData().class_id = _class_id;
GetData().changed_class = _class_id > 0;
if (GetData().changed_class) {
GetData().battler_animation = GetClass()->battler_animation;
} else {
GetData().battler_animation = 0;
}
MakeExpList();
}

std::string Game_Actor::GetClassName() const {
if (GetClass() <= 0) {
if (!GetClass()) {
return "";
}
return Data::classes[GetClass() - 1].name;
return GetClass()->name;
}

void Game_Actor::SetBaseMaxHp(int maxhp) {
Expand Down Expand Up @@ -940,7 +954,26 @@ int Game_Actor::GetBattleAnimationId() const {
return 0;
}

return Data::battleranimations[Data::actors[actor_id - 1].battler_animation - 1].ID;
int anim = 0;

if (GetData().battler_animation <= 0) {
// Earlier versions of EasyRPG didn't save this value correctly

if (GetData().class_id > 0) {
anim = GetClass()->battler_animation;
} else {
anim = Data::battleranimations[Data::actors[actor_id - 1].battler_animation - 1].ID;
}
} else {
anim = GetData().battler_animation;
}

if (anim == 0) {
// Chunk was missing, set to proper default
return 1;
}

return anim;
}

int Game_Actor::GetHitChance() const {
Expand Down
4 changes: 3 additions & 1 deletion src/game_actor.h
Expand Up @@ -28,6 +28,7 @@ namespace RPG {
class Skill;
class BattleCommand;
class Item;
class Class;
}

/**
Expand Down Expand Up @@ -636,7 +637,8 @@ class Game_Actor : public Game_Battler {
*
* @return Rpg2k3 hero class.
*/
int GetClass() const;
const RPG::Class* GetClass() const;

/**
* Sets new Rpg2k3 hero class.
*
Expand Down
34 changes: 33 additions & 1 deletion src/game_battle.cpp
Expand Up @@ -54,6 +54,8 @@ namespace {
std::vector<bool> page_executed;
int terrain_id;
int battle_mode;
int target_enemy_index;
bool need_refresh;
}

void Game_Battle::Init() {
Expand All @@ -65,6 +67,8 @@ void Game_Battle::Init() {
turn = 0;
terminate = false;
escape_fail_count = 0;
target_enemy_index = 0;
need_refresh = false;

troop = &Data::troops[Game_Temp::battle_troop_id - 1];
page_executed.resize(troop->pages.size());
Expand Down Expand Up @@ -109,6 +113,18 @@ void Game_Battle::Update() {
animation.reset();
}
}
if (need_refresh) {
need_refresh = false;
std::vector<Game_Battler*> battlers;
(*Main_Data::game_party).GetBattlers(battlers);
(*Main_Data::game_enemyparty).GetBattlers(battlers);
for (Game_Battler* b : battlers) {
Sprite_Battler* spr = spriteset->FindBattler(b);
if (spr) {
spr->DetectStateChange();
}
}
}
}

void Game_Battle::Terminate() {
Expand Down Expand Up @@ -168,8 +184,12 @@ void Game_Battle::NextTurn(Game_Battler* battler) {
page_executed[(*it).ID - 1] = false;
}
}

battler->SetLastBattleAction(-1);
}

Game_Battle::SetEnemyTargetIndex(-1);

++turn;
}

Expand All @@ -187,7 +207,7 @@ void Game_Battle::UpdateGauges() {

for (std::vector<Game_Battler*>::const_iterator it = battlers.begin();
it != battlers.end(); ++it) {
if (!(*it)->GetBattleAlgorithm()) {
if (!(*it)->GetBattleAlgorithm() && (*it)->CanAct()) {
(*it)->UpdateGauge(1000 / max_agi);
}
}
Expand Down Expand Up @@ -336,3 +356,15 @@ void Game_Battle::SetBattleMode(int battle_mode_) {
int Game_Battle::GetBattleMode() {
return battle_mode;
}

void Game_Battle::SetEnemyTargetIndex(int target_enemy) {
target_enemy_index = target_enemy;
}

int Game_Battle::GetEnemyTargetIndex() {
return target_enemy_index;
}

void Game_Battle::SetNeedRefresh(bool refresh) {
need_refresh = refresh;
}
22 changes: 22 additions & 0 deletions src/game_battle.h
Expand Up @@ -109,6 +109,28 @@ namespace Game_Battle {
void SetBattleMode(int battle_mode_);
int GetBattleMode();

/**
* Sets the party index of the latest targeted enemy. Only used by battle branch "is target"
*
* @param target_enemy id of targeted enemy
*/
void SetEnemyTargetIndex(int target_enemy);

/**
* Gets the party index of the latest targeted enemy. Only used by battle branch "is target"
*
* @return targeted enemy
*/
int GetEnemyTargetIndex();

/**
* Sets the need refresh flag.
* This flag is set when the interpreter altered the state of enemies (e.g. dead)
*
* @param need_refresh need refresh state.
*/
void SetNeedRefresh(bool refresh);

extern int escape_fail_count;
extern std::string background_name;
}

0 comments on commit a16f258

Please sign in to comment.