|
34 | 34 | #include "output.h" |
35 | 35 | #include <cmath> |
36 | 36 | #include <cassert> |
37 | | -#include <optional> |
38 | 37 |
|
39 | 38 | Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) : |
40 | 39 | Game_EventBase(Event), |
@@ -310,10 +309,9 @@ bool Game_Event::WasStartedByDecisionKey() const { |
310 | 309 | return data()->triggered_by_decision_key; |
311 | 310 | } |
312 | 311 |
|
313 | | -std::optional<lcf::rpg::EventPage::Trigger> Game_Event::GetTrigger() const { |
314 | | - if (page) |
315 | | - return static_cast<lcf::rpg::EventPage::Trigger>(page->trigger); |
316 | | - return std::nullopt; |
| 312 | +lcf::rpg::EventPage::Trigger Game_Event::GetTrigger() const { |
| 313 | + int trigger = page ? page->trigger : -1; |
| 314 | + return static_cast<lcf::rpg::EventPage::Trigger>(trigger); |
317 | 315 | } |
318 | 316 |
|
319 | 317 |
|
@@ -356,69 +354,81 @@ bool Game_Event::CheckEventAutostart() { |
356 | 354 | } |
357 | 355 |
|
358 | 356 | bool Game_Event::CheckEventCollision() { |
359 | | - if (GetTrigger() == lcf::rpg::EventPage::Trigger_collision |
360 | | - && GetLayer() != lcf::rpg::EventPage::Layers_same |
361 | | - && !Main_Data::game_player->IsMoveRouteOverwritten() |
362 | | - && !Game_Map::GetInterpreter().IsRunning()) |
363 | | - { |
364 | | - // Iterate through our own footprint to see if any tile hits the (potentially large) player |
365 | | - int min_dx, max_dx, min_dy, max_dy; |
366 | | - GetTileOffsets(min_dx, max_dx, min_dy, max_dy); |
| 357 | + if (GetTrigger() == lcf::rpg::EventPage::Trigger_collision |
| 358 | + && GetLayer() != lcf::rpg::EventPage::Layers_same |
| 359 | + && !Main_Data::game_player->IsMoveRouteOverwritten() |
| 360 | + && !Game_Map::GetInterpreter().IsRunning()) |
| 361 | + { |
| 362 | + int x1, x2, y1, y2; |
| 363 | + GetTileOffsets(x1, x2, y1, y2); |
| 364 | + bool is_expanded = (x1 != 0 || x2 != 0 || y1 != 0 || y2 != 0); |
367 | 365 |
|
368 | | - for (int dy = min_dy; dy <= max_dy; ++dy) { |
369 | | - for (int dx = min_dx; dx <= max_dx; ++dx) { |
370 | | - if (Main_Data::game_player->IsInPosition(Game_Map::RoundX(GetX() + dx), Game_Map::RoundY(GetY() + dy))) { |
371 | | - ScheduleForegroundExecution(false, true); |
372 | | - SetStopCount(0); |
373 | | - return true; |
374 | | - } |
375 | | - } |
376 | | - } |
377 | | - } |
378 | | - return false; |
| 366 | + if (!is_expanded) { |
| 367 | + // Standard logic |
| 368 | + if (Main_Data::game_player->GetX() == GetX() && Main_Data::game_player->GetY() == GetY()) { |
| 369 | + ScheduleForegroundExecution(false, true); |
| 370 | + SetStopCount(0); |
| 371 | + return true; |
| 372 | + } |
| 373 | + return false; |
| 374 | + } |
| 375 | + |
| 376 | + for (int dy = y1; dy <= y2; ++dy) { |
| 377 | + for (int dx = x1; dx <= x2; ++dx) { |
| 378 | + if (Main_Data::game_player->IsInPosition(Game_Map::RoundX(GetX() + dx), Game_Map::RoundY(GetY() + dy))) { |
| 379 | + ScheduleForegroundExecution(false, true); |
| 380 | + SetStopCount(0); |
| 381 | + return true; |
| 382 | + } |
| 383 | + } |
| 384 | + } |
| 385 | + } |
| 386 | + return false; |
379 | 387 | } |
380 | 388 |
|
381 | 389 | void Game_Event::CheckCollisonOnMoveFailure() { |
382 | | - if (Game_Map::GetInterpreter().IsRunning()) return; |
383 | | - |
384 | | - int min_dx, max_dx, min_dy, max_dy; |
385 | | - GetTileOffsets(min_dx, max_dx, min_dy, max_dy); |
386 | | - |
387 | | - int direction = GetDirection(); |
| 390 | + if (Game_Map::GetInterpreter().IsRunning()) return; |
388 | 391 |
|
389 | | - // Scan leading edge of event |
390 | | - if (direction == Up || direction == Down) { |
391 | | - int target_dy = (direction == Up) ? min_dy : max_dy; |
392 | | - for (int dx = min_dx; dx <= max_dx; ++dx) { |
393 | | - int fx = Game_Map::RoundX(GetX() + dx); |
394 | | - int fy = Game_Map::RoundY(Game_Map::YwithDirection(GetY() + target_dy, direction)); |
| 392 | + int x1, x2, y1, y2; |
| 393 | + GetTileOffsets(x1, x2, y1, y2); |
| 394 | + bool is_expanded = (x1 != 0 || x2 != 0 || y1 != 0 || y2 != 0); |
395 | 395 |
|
396 | | - if (Main_Data::game_player->IsInPosition(fx, fy) && |
397 | | - GetLayer() == lcf::rpg::EventPage::Layers_same && |
398 | | - GetTrigger() == lcf::rpg::EventPage::Trigger_collision) |
399 | | - { |
400 | | - ScheduleForegroundExecution(false, true); |
401 | | - SetStopCount(0); |
402 | | - return; |
403 | | - } |
404 | | - } |
405 | | - } |
406 | | - else if (direction == Left || direction == Right) { |
407 | | - int target_dx = (direction == Left) ? min_dx : max_dx; |
408 | | - for (int dy = min_dy; dy <= max_dy; ++dy) { |
409 | | - int fx = Game_Map::RoundX(Game_Map::XwithDirection(GetX() + target_dx, direction)); |
410 | | - int fy = Game_Map::RoundY(GetY() + dy); |
| 396 | + if (!is_expanded) { |
| 397 | + // Standard logic |
| 398 | + int fx = Game_Map::XwithDirection(GetX(), GetDirection()); |
| 399 | + int fy = Game_Map::YwithDirection(GetY(), GetDirection()); |
| 400 | + if (Main_Data::game_player->GetX() == fx && Main_Data::game_player->GetY() == fy && |
| 401 | + GetLayer() == lcf::rpg::EventPage::Layers_same && GetTrigger() == lcf::rpg::EventPage::Trigger_collision) { |
| 402 | + ScheduleForegroundExecution(false, true); |
| 403 | + SetStopCount(0); |
| 404 | + } |
| 405 | + return; |
| 406 | + } |
411 | 407 |
|
412 | | - if (Main_Data::game_player->IsInPosition(fx, fy) && |
413 | | - GetLayer() == lcf::rpg::EventPage::Layers_same && |
414 | | - GetTrigger() == lcf::rpg::EventPage::Trigger_collision) |
415 | | - { |
416 | | - ScheduleForegroundExecution(false, true); |
417 | | - SetStopCount(0); |
418 | | - return; |
419 | | - } |
420 | | - } |
421 | | - } |
| 408 | + int dir = GetDirection(); |
| 409 | + if (dir == Up || dir == Down) { |
| 410 | + int target_dy = (dir == Up) ? y1 : y2; |
| 411 | + for (int dx = x1; dx <= x2; ++dx) { |
| 412 | + int fx = Game_Map::RoundX(GetX() + dx); |
| 413 | + int fy = Game_Map::RoundY(Game_Map::YwithDirection(GetY() + target_dy, dir)); |
| 414 | + if (Main_Data::game_player->IsInPosition(fx, fy) && GetLayer() == lcf::rpg::EventPage::Layers_same && GetTrigger() == lcf::rpg::EventPage::Trigger_collision) { |
| 415 | + ScheduleForegroundExecution(false, true); |
| 416 | + SetStopCount(0); |
| 417 | + return; |
| 418 | + } |
| 419 | + } |
| 420 | + } else { |
| 421 | + int target_dx = (dir == Left) ? x1 : x2; |
| 422 | + for (int dy = y1; dy <= y2; ++dy) { |
| 423 | + int fx = Game_Map::RoundX(Game_Map::XwithDirection(GetX() + target_dx, dir)); |
| 424 | + int fy = Game_Map::RoundY(GetY() + dy); |
| 425 | + if (Main_Data::game_player->IsInPosition(fx, fy) && GetLayer() == lcf::rpg::EventPage::Layers_same && GetTrigger() == lcf::rpg::EventPage::Trigger_collision) { |
| 426 | + ScheduleForegroundExecution(false, true); |
| 427 | + SetStopCount(0); |
| 428 | + return; |
| 429 | + } |
| 430 | + } |
| 431 | + } |
422 | 432 | } |
423 | 433 |
|
424 | 434 | bool Game_Event::Move(int dir) { |
|
0 commit comments