Skip to content

Commit

Permalink
Changes on Erase Event - Maniacs Patch + Destroy Mode
Browse files Browse the repository at this point in the history
Erase Event now have a Destroy Map Event Operator when param[1] == 2;

Still a few bugs when running on parallel process or destroying itself.
  • Loading branch information
jetrotal committed May 8, 2024
1 parent a3dcaa6 commit b87cafd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ inline Game_CharacterDataStorage<T>::Game_CharacterDataStorage(Game_CharacterDat
template <typename T>
inline Game_CharacterDataStorage<T>& Game_CharacterDataStorage<T>::operator=(Game_CharacterDataStorage&& o) noexcept
{
static_cast<Game_Character*>(this) = std::move(o);
if (this != &o) {
_data = std::move(o._data);
Game_Character::_data = &this->_data;
Expand Down
12 changes: 9 additions & 3 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3917,11 +3917,14 @@ bool Game_Interpreter::CommandEndLoop(lcf::rpg::EventCommand const& com) { // co
return true;
}

bool Game_Interpreter::CommandEraseEvent(lcf::rpg::EventCommand const& /* com */) { // code 12320
bool Game_Interpreter::CommandEraseEvent(lcf::rpg::EventCommand const& com) { // code 12320
auto& frame = GetFrame();
auto& index = frame.current_command;

auto event_id = GetThisEventId();
int operation = Player::IsPatchManiac() ? com.parameters[1] : 0;

int event_id = Player::IsPatchManiac() ? ValueOrVariableBitfield(com.parameters[0], 1, com.parameters[2]) : 0;
if(event_id == 0 || event_id == Game_Character::CharThisEvent) event_id = GetThisEventId();

// When a common event and not RPG2k3E engine ignore the call, otherwise
// operate on last map_event
Expand All @@ -3930,7 +3933,10 @@ bool Game_Interpreter::CommandEraseEvent(lcf::rpg::EventCommand const& /* com */

Game_Event* evnt = Game_Map::GetEvent(event_id);
if (evnt) {
evnt->SetActive(false);

if (operation == 1) evnt->SetActive(true);
else if (operation == 2) Game_Map::DestroyMapEvent(event_id);
else evnt->SetActive(false);

// Parallel map events shall stop immediately
if (!main_flag) {
Expand Down
52 changes: 52 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,58 @@ bool Game_Map::CloneMapEvent(int src_map_id, int src_event_id, int target_x, int

Scene_Map* scene = (Scene_Map*)Scene::Find(Scene::Map).get();
scene->spriteset->Refresh();
SetNeedRefresh(true);

return true;
}

bool Game_Map::DestroyMapEvent(const int event_id) {
const lcf::rpg::Event* event = FindEventById(map->events, event_id);

if (event == nullptr) {
Output::Warning("DestroyMapEvent: Event ID {} not found on current map", event_id);
return true;
}

// Remove event from cache
// for (auto& pg : event->pages) {
// if (pg.condition.flags.switch_a) {
// events_cache_by_switch[pg.condition.switch_a_id].RemoveEvent(*event);
// }
// if (pg.condition.flags.switch_b) {
// events_cache_by_switch[pg.condition.switch_b_id].RemoveEvent(*event);
// }
// if (pg.condition.flags.variable) {
// events_cache_by_variable[pg.condition.variable_id].RemoveEvent(*event);
// }
// }


// Remove event from events vector
auto it = events.end();
for (auto iter = events.begin(); iter != events.end(); ++iter) {
if (iter->GetId() == event_id) {
it = iter;
break;
}
}
if (it != events.end()) {
events.erase(it);
}

// Remove event from map
for (auto it = map->events.begin(); it != map->events.end(); ++it) {
if (it->ID == event_id) {
map->events.erase(it);
break;
}
}

FixUnderlyingEventReferences();

Scene_Map* scene = (Scene_Map*)Scene::Find(Scene::Map).get();
scene->spriteset->Refresh();
SetNeedRefresh(true);

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ namespace Game_Map {
void Dispose();

bool CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y);
bool DestroyMapEvent(const int event_id);

void TranslateMapMessages(int mapId, lcf::rpg::Map& map);
void CreateMapEvents();
inline void FixUnderlyingEventReferences();
Expand Down

0 comments on commit b87cafd

Please sign in to comment.