Skip to content

Commit 979777f

Browse files
Larger Events Version 3
Resolved the whitespace/formatting issues, make the new code a branch off the original so it only executes when it the game detects a {_X} or a {!Y} string in the filename of a charset and restored the original CheckOrMakeWayEx code and made the larger events a branch so nothing gets broken down the way.
1 parent 567b1bd commit 979777f

5 files changed

Lines changed: 372 additions & 276 deletions

File tree

src/game_character.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ bool Game_Character::CalculateMoveRoute(const CalculateMoveRouteArgs& args) {
833833
std::unordered_map<int, SearchNode> graph;
834834
std::map<std::pair<int, int>, SearchNode> graph_by_coord;
835835
queue.push_back(start);
836+
int id = 0;
836837
int idd = 0;
837838
int steps_taken = 0;
838839
SearchNode closest_node = {args.dest_x, args.dest_y, std::numeric_limits<int>::max(), -1}; // Initialize with a very high cost.
@@ -998,7 +999,7 @@ bool Game_Character::CalculateMoveRoute(const CalculateMoveRouteArgs& args) {
998999
}
9991000
}
10001001
}
1001-
1002+
id++;
10021003
// Calculate the Manhattan distance between the current node and the destination
10031004
int manhattan_dist = abs(args.dest_x - n.x) + abs(args.dest_y - n.y);
10041005

@@ -1277,39 +1278,32 @@ float Game_Character::GetHitboxRadius() const {
12771278
}
12781279

12791280
bool Game_Character::IsInPosition(int x, int y) const {
1280-
int x1, x2, y1, y2;
1281-
GetTileOffsets(x1, x2, y1, y2);
1281+
int x1, x2, y1, y2;
1282+
GetTileOffsets(x1, x2, y1, y2);
1283+
bool is_expanded = (x1 != 0 || x2 != 0 || y1 != 0 || y2 != 0);
12821284

1283-
int left = GetX() + x1;
1284-
int right = GetX() + x2;
1285-
int top = GetY() + y1;
1286-
int bottom = GetY() + y2;
1285+
if (!is_expanded) {
1286+
// Standard Branch: Exact coordinate match
1287+
return GetX() == x && GetY() == y;
1288+
}
12871289

1288-
if (Game_Map::LoopVertical()) {
1289-
int h = Game_Map::GetTilesY();
1290-
bool found_y = false;
1291-
for (int j = top; j <= bottom; ++j) {
1292-
if (Utils::PositiveModulo(j, h) == y) {
1293-
found_y = true;
1294-
break;
1295-
}
1296-
}
1297-
if (!found_y) return false;
1298-
} else if (y < top || y > bottom) {
1299-
return false;
1300-
}
1290+
// Extended Branch: Rectangle footprint match
1291+
if (GetY() + y1 > y || GetY() + y2 < y) {
1292+
return false;
1293+
}
13011294

1302-
if (Game_Map::LoopHorizontal()) {
1303-
int w = Game_Map::GetTilesX();
1304-
for (int i = left; i <= right; ++i) {
1305-
if (Utils::PositiveModulo(i, w) == x) {
1306-
return true;
1307-
}
1308-
}
1309-
return false;
1310-
}
1295+
int left_edge = GetX() + x1;
1296+
int right_edge = GetX() + x2;
1297+
1298+
if (Game_Map::LoopHorizontal()) {
1299+
int map_w = Game_Map::GetTilesX();
1300+
for (int i = left_edge; i <= right_edge; ++i) {
1301+
if (Utils::PositiveModulo(i, map_w) == x) return true;
1302+
}
1303+
return false;
1304+
}
13111305

1312-
return x >= left && x <= right;
1306+
return x >= left_edge && x <= right_edge;
13131307
}
13141308

13151309
int Game_Character::GetOpacity() const {

src/game_character.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -815,17 +815,30 @@ class Game_Character {
815815
* @param x X tile position
816816
* @param y Y tile position
817817
* @return If on tile or moving towards
818-
*/
818+
*/
819+
819820
virtual bool IsInPosition(int x, int y) const;
820821

821-
int GetTileWidth() const;
822-
int GetTileHeight() const;
823-
float GetHitboxRadius() const;
822+
/**
823+
* Calculates the relative tile offsets based on filename tags.
824+
* min_dx/max_dx handle horizontal ({_#}) and min_dy/max_dy handle vertical ({!#}).
825+
*/
826+
void GetTileOffsets(int& min_dx, int& max_dx, int& min_dy, int& max_dy) const;
824827

825-
void GetTileOffsets(int& min_dx, int& max_dx, int& min_dy, int& max_dy) const;
826-
float GetHitboxCenterX() const;
827-
float GetHitboxCenterY() const;
828-
828+
/** Returns the total width of the character in 16px tiles. */
829+
int GetTileWidth() const;
830+
831+
/** Returns the total height of the character in 16px tiles. */
832+
int GetTileHeight() const;
833+
834+
/** Returns the collision radius in units (1.0 = 16px) for pixel movement. */
835+
float GetHitboxRadius() const;
836+
837+
/** Returns the absolute X center of the expanded hitbox in logical units. */
838+
float GetHitboxCenterX() const;
839+
840+
/** Returns the absolute Y center of the expanded hitbox in logical units. */
841+
float GetHitboxCenterY() const;
829842

830843
/**
831844
* Gets current opacity of character.

src/game_event.cpp

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "output.h"
3535
#include <cmath>
3636
#include <cassert>
37-
#include <optional>
3837

3938
Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) :
4039
Game_EventBase(Event),
@@ -310,10 +309,9 @@ bool Game_Event::WasStartedByDecisionKey() const {
310309
return data()->triggered_by_decision_key;
311310
}
312311

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);
317315
}
318316

319317

@@ -356,69 +354,81 @@ bool Game_Event::CheckEventAutostart() {
356354
}
357355

358356
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);
367365

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;
379387
}
380388

381389
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;
388391

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);
395395

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+
}
411407

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+
}
422432
}
423433

424434
bool Game_Event::Move(int dir) {

0 commit comments

Comments
 (0)