Skip to content

Commit

Permalink
Spawn Map Event - Destroy Map Event Operator (WIP)
Browse files Browse the repository at this point in the history
It happens when src_map is smaller than 0.

The line bellow needs some work, it's hitting a compiler error when uncommented
	if (it != events.end()) {
		//events.erase(it);
	}
  • Loading branch information
jetrotal committed May 8, 2024
1 parent a3dcaa6 commit 977c5ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5118,7 +5118,9 @@ bool Game_Interpreter::CommandSpawnMapEvent(lcf::rpg::EventCommand const& com) {

if (src_map == 0) src_map = Game_Map::GetMapId();

Game_Map::CloneMapEvent(src_map, src_event, target_x, target_y);
if (src_map <= -1) Game_Map::DestroyMapEvent(src_event);
else Game_Map::CloneMapEvent(src_map, src_event, target_x, target_y);

return true;
}

Expand Down
50 changes: 50 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,56 @@ 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 false;
}

// 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;
}
}

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 977c5ad

Please sign in to comment.