Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/game_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "output.h"
#include <cmath>
#include <cassert>
#include <optional>

Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) :
Game_EventBase(Event),
Expand Down Expand Up @@ -309,9 +310,10 @@ bool Game_Event::WasStartedByDecisionKey() const {
return data()->triggered_by_decision_key;
}

lcf::rpg::EventPage::Trigger Game_Event::GetTrigger() const {
int trigger = page ? page->trigger : -1;
return static_cast<lcf::rpg::EventPage::Trigger>(trigger);
std::optional<lcf::rpg::EventPage::Trigger> Game_Event::GetTrigger() const {
if (page)
return static_cast<lcf::rpg::EventPage::Trigger>(page->trigger);
return std::nullopt;
}


Expand Down
3 changes: 2 additions & 1 deletion src/game_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define EP_GAME_EVENT_H

// Headers
#include <optional>
#include <string>
#include <vector>
#include "game_character.h"
Expand Down Expand Up @@ -99,7 +100,7 @@ class Game_Event : public Game_EventBase {
*
* @return trigger condition.
*/
lcf::rpg::EventPage::Trigger GetTrigger() const;
std::optional<lcf::rpg::EventPage::Trigger> GetTrigger() const;

/**
* Gets event commands list.
Expand Down
12 changes: 7 additions & 5 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,8 @@ bool Game_Map::UpdateForegroundEvents(MapUpdateAsyncContext& actx) {
if (run_ev) {
if (run_ev->WasStartedByDecisionKey()) {
interp.Push<InterpreterExecutionType::Action>(run_ev);
} else {
switch (run_ev->GetTrigger()) {
} else if (auto t = run_ev->GetTrigger()) {
switch (*t) {
case lcf::rpg::EventPage::Trigger_touched:
interp.Push<InterpreterExecutionType::Touch>(run_ev);
break;
Expand All @@ -1464,10 +1464,12 @@ bool Game_Map::UpdateForegroundEvents(MapUpdateAsyncContext& actx) {
interp.Push<InterpreterExecutionType::AutoStart>(run_ev);
break;
case lcf::rpg::EventPage::Trigger_action:
default:
case lcf::rpg::EventPage::Trigger_parallel:
interp.Push<InterpreterExecutionType::Action>(run_ev);
break;
}
} else {
interp.Push<InterpreterExecutionType::Action>(run_ev);
}
run_ev->ClearWaitingForegroundExecution();
}
Expand Down Expand Up @@ -1723,7 +1725,7 @@ void Game_Map::SetPositionX(int x, bool reset_panorama) {
const int map_width = GetTilesX() * SCREEN_TILE_SIZE;
if (LoopHorizontal()) {
x = Utils::PositiveModulo(x, map_width);

// If the map is too small to fit in the screen, add an offset corresponding to the black border's size
if (Player::game_config.fake_resolution.Get()) {
int map_width_in_pixels = Game_Map::GetTilesX() * TILE_SIZE;
Expand Down Expand Up @@ -2157,7 +2159,7 @@ void Game_Map::Parallax::ResetPositionX() {
if (!params.scroll_horz && !LoopHorizontal()) {
// What is the width of the panorama to display on screen?
int pan_screen_width = Player::screen_width;
if (Player::game_config.fake_resolution.Get()) {
if (Player::game_config.fake_resolution.Get()) {
int map_width = Game_Map::GetTilesX() * TILE_SIZE;
if (map_width < pan_screen_width) {
pan_screen_width = map_width;
Expand Down
8 changes: 4 additions & 4 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ bool Game_Player::CheckEventTriggerHere(TriggerSet triggers, bool triggered_by_d
&& ev.GetX() == GetX()
&& ev.GetY() == GetY()
&& ev.GetLayer() != lcf::rpg::EventPage::Layers_same
&& trigger >= 0
&& triggers[trigger]) {
&& trigger.has_value()
&& triggers[*trigger]) {
SetEncounterCalling(false);
result |= ev.ScheduleForegroundExecution(triggered_by_decision_key, face_player);
}
Expand All @@ -480,8 +480,8 @@ bool Game_Player::CheckEventTriggerThere(TriggerSet triggers, int x, int y, bool
&& ev.GetX() == x
&& ev.GetY() == y
&& ev.GetLayer() == lcf::rpg::EventPage::Layers_same
&& trigger >= 0
&& triggers[trigger]) {
&& trigger.has_value()
&& triggers[*trigger]) {
SetEncounterCalling(false);
result |= ev.ScheduleForegroundExecution(triggered_by_decision_key, face_player);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "game_vehicle.h"
#include "doctest.h"
#include <climits>
#include <optional>

static_assert(Game_Character::GetMaxStopCountForStep(1) == 256, "StopCountBroken");
static_assert(Game_Character::GetMaxStopCountForStep(2) == 128, "StopCountBroken");
Expand Down Expand Up @@ -225,7 +226,7 @@ TEST_CASE("InitEventNoPage") {

REQUIRE(!ch.IsWaitingForegroundExecution());
REQUIRE(!ch.WasStartedByDecisionKey());
REQUIRE_EQ(ch.GetTrigger(), -1);
REQUIRE_EQ(ch.GetTrigger(), std::nullopt);
REQUIRE_EQ(ch.GetOriginalMoveRouteIndex(), 0);
REQUIRE_EQ(ch.GetPage(1), nullptr);
REQUIRE_EQ(ch.GetActivePage(), nullptr);
Expand Down
Loading