Skip to content

Commit

Permalink
Merge pull request #1470 from fmatthew5876/lsd_defaults
Browse files Browse the repository at this point in the history
SaveGame Fixes
  • Loading branch information
Ghabry authored Nov 5, 2018
2 parents 7d43de4 + eee93f1 commit 4c589a4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/game_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,18 @@ std::vector<int16_t>& Game_Actor::GetStates() {

void Game_Actor::AddState(int state_id) {
Game_Battler::AddState(state_id);
GetData().status_size = GetData().status.size();
}

void Game_Actor::RemoveState(int state_id) {
Game_Battler::RemoveState(state_id);
GetData().status_size = GetData().status.size();
}

void Game_Actor::RemoveBattleStates() {
Game_Battler::RemoveBattleStates();
GetData().status_size = GetData().status.size();
}

void Game_Actor::RemoveAllStates() {
Game_Battler::RemoveAllStates();
GetData().status_size = GetData().status.size();
}

int Game_Actor::GetHp() const {
Expand Down
14 changes: 6 additions & 8 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,10 +2535,9 @@ bool Game_Interpreter::CommandTeleportTargets(RPG::EventCommand const& com) { //

int x = com.parameters[2];
int y = com.parameters[3];
int switch_id = (com.parameters[4] != 0)
? com.parameters[5]
: -1;
Game_Targets::AddTeleportTarget(map_id, x, y, switch_id);
bool switch_on = static_cast<bool>(com.parameters[4]);
int switch_id = com.parameters[5];
Game_Targets::AddTeleportTarget(map_id, x, y, switch_on, switch_id);
return true;
}

Expand All @@ -2551,10 +2550,9 @@ bool Game_Interpreter::CommandEscapeTarget(RPG::EventCommand const& com) { // co
int map_id = com.parameters[0];
int x = com.parameters[1];
int y = com.parameters[2];
int switch_id = (com.parameters[3] != 0)
? com.parameters[4]
: -1;
Game_Targets::SetEscapeTarget(map_id, x, y, switch_id);
bool switch_on = static_cast<bool>(com.parameters[3]);
int switch_id = com.parameters[4];
Game_Targets::SetEscapeTarget(map_id, x, y, switch_on, switch_id);
return true;
}

Expand Down
15 changes: 11 additions & 4 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ void Game_Map::Quit() {

void Game_Map::Setup(int _id) {
SetupCommon(_id, false);
map_info.encounter_rate = GetMapInfo().encounter_steps;
ResetEncounterSteps();

Parallax::ClearChangedBG();

Expand Down Expand Up @@ -197,9 +199,12 @@ void Game_Map::SetupFromSave() {
if (vehicles[i]->IsMoveRouteOverwritten())
pending.push_back(vehicles[i].get());

map_info.Fixup(*map.get());
map_info.Fixup(GetMap());
map_info.Fixup(GetMapInfo());
SetChipset(map_info.chipset_id);

ResetEncounterSteps();

// FIXME: Handle Pan correctly
location.pan_current_x = 0;
location.pan_current_y = 0;
Expand Down Expand Up @@ -236,7 +241,6 @@ void Game_Map::SetupCommon(int _id, bool is_load_savegame) {
refresh_type = Refresh_All;

int current_index = GetMapIndex(location.map_id);
map_info.encounter_rate = Data::treemap.maps[current_index].encounter_steps;

ss.str("");
for (int cur = current_index;
Expand Down Expand Up @@ -278,8 +282,6 @@ void Game_Map::SetupCommon(int _id, bool is_load_savegame) {
// events will properly resume upon loading.
location.map_save_count = map_save_count;
location.database_save_count = Data::system.save_count;

ResetEncounterSteps();
}

void Game_Map::PrepareSave() {
Expand Down Expand Up @@ -867,6 +869,11 @@ void Game_Map::Update(bool only_parallel) {
free_interpreters.clear();
}

RPG::MapInfo const& Game_Map::GetMapInfo() {
auto idx = GetMapIndex(location.map_id);
return Data::treemap.maps[idx];
}

RPG::Map const& Game_Map::GetMap() {
return *map;
}
Expand Down
8 changes: 8 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "game_vehicle.h"
#include "rpg_encounter.h"
#include "rpg_map.h"
#include "rpg_mapinfo.h"

class FileRequestAsync;

Expand Down Expand Up @@ -229,6 +230,13 @@ namespace Game_Map {
*/
void Update(bool only_parallel = false);

/**
* Gets current map_info.
*
* @return current map_info.
*/
RPG::MapInfo const& GetMapInfo();

/**
* Gets current map.
*
Expand Down
15 changes: 7 additions & 8 deletions src/game_targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ std::vector<RPG::SaveTarget>::iterator Game_Targets::FindTarget(int id, bool cre
return data.end() - 1;
}

void Game_Targets::AddTeleportTarget(int map_id, int x, int y, int switch_id) {
void Game_Targets::AddTeleportTarget(int map_id, int x, int y, bool switch_on, int switch_id) {
std::vector<RPG::SaveTarget>::iterator target = FindTarget(map_id, true);

target->map_id = map_id;
target->map_x = x;
target->map_y = y;
target->switch_on = switch_id > 0;
target->switch_on = switch_on;
target->switch_id = switch_id;
}

Expand Down Expand Up @@ -86,22 +86,21 @@ std::vector<RPG::SaveTarget*> Game_Targets::GetTeleportTargets() {
return targets;
}

void Game_Targets::SetEscapeTarget(int map_id, int x, int y, int switch_id) {
std::vector<RPG::SaveTarget>::iterator target = FindTarget(0, true);
void Game_Targets::SetEscapeTarget(int map_id, int x, int y, bool switch_on, int switch_id) {
auto* target = &data[0];

target->map_id = map_id;
target->map_x = x;
target->map_y = y;
target->switch_on = switch_id > 0;
target->switch_on = switch_on;
target->switch_id = switch_id;
}

bool Game_Targets::HasEscapeTarget() {
return GetEscapeTarget() != nullptr;
return data[0].map_id != 0;
}

RPG::SaveTarget* Game_Targets::GetEscapeTarget() {
std::vector<RPG::SaveTarget>::iterator target = FindTarget(0, false);
return target == data.end() ? NULL : &*target;
return HasEscapeTarget() ? &data[0] : nullptr;
}

4 changes: 2 additions & 2 deletions src/game_targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace RPG {
}

namespace Game_Targets {
void AddTeleportTarget(int map_id, int x, int y, int switch_id);
void AddTeleportTarget(int map_id, int x, int y, bool switch_on, int switch_id);
void RemoveTeleportTarget(int map_id);
bool HasTeleportTarget();
RPG::SaveTarget* GetTeleportTarget(int map_id);
std::vector<RPG::SaveTarget*> GetTeleportTargets();
void SetEscapeTarget(int map_id, int x, int y, int switch_id);
void SetEscapeTarget(int map_id, int x, int y, bool switch_on, int switch_id);
bool HasEscapeTarget();
RPG::SaveTarget* GetEscapeTarget();
}
Expand Down
5 changes: 4 additions & 1 deletion src/scene_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ void Scene_Save::Action(int index) {
}

LSD_Reader::PrepareSave(Main_Data::game_data);
LSD_Reader::Save(filename, Main_Data::game_data, Player::encoding);
auto data_copy = LSD_Reader::ClearDefaults(Main_Data::game_data, Game_Map::GetMapInfo(), Game_Map::GetMap());
// RPG_RT saves always have the scene set to this.
data_copy.system.scene = RPG::SaveSystem::Scene_file;
LSD_Reader::Save(filename, data_copy, Player::encoding);

#ifdef EMSCRIPTEN
// Save changed file system
Expand Down

0 comments on commit 4c589a4

Please sign in to comment.