yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_exit.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_OVERWORLD_EXIT_H
2#define YAZE_APP_ZELDA3_OVERWORLD_EXIT_H
3
4#include <algorithm>
5#include <cstdint>
6#include <cstdlib>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "rom/rom.h"
11#include "zelda3/common.h"
13
14namespace yaze::zelda3 {
15
16// Forward declaration to avoid circular dependency
17class Overworld;
18
19constexpr int kNumOverworldExits = 0x4F;
20constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences
21// 105C2 Ending maps
22// 105E2 Sprite Group Table for Ending
23constexpr int OWExitMapId = 0x15E28;
24constexpr int OWExitVram = 0x15E77;
25constexpr int OWExitYScroll = 0x15F15;
26constexpr int OWExitXScroll = 0x15FB3;
27constexpr int OWExitYPlayer = 0x16051;
28constexpr int OWExitXPlayer = 0x160EF;
29constexpr int OWExitYCamera = 0x1618D;
30constexpr int OWExitXCamera = 0x1622B;
31constexpr int OWExitDoorPosition = 0x15724;
32constexpr int OWExitUnk1 = 0x162C9;
33constexpr int OWExitUnk2 = 0x16318;
34constexpr int OWExitDoorType1 = 0x16367;
35constexpr int OWExitDoorType2 = 0x16405;
36
37constexpr int OWExitMapIdWhirlpool = 0x16AE5; // JP = ;016849
38constexpr int OWExitVramWhirlpool = 0x16B07; // JP = ;01686B
39constexpr int OWExitYScrollWhirlpool = 0x16B29; // JP = ;01688D
40constexpr int OWExitXScrollWhirlpool = 0x16B4B; // JP = ;016DE7
41constexpr int OWExitYPlayerWhirlpool = 0x16B6D; // JP = ;016E09
42constexpr int OWExitXPlayerWhirlpool = 0x16B8F; // JP = ;016E2B
43constexpr int OWExitYCameraWhirlpool = 0x16BB1; // JP = ;016E4D
44constexpr int OWExitXCameraWhirlpool = 0x16BD3; // JP = ;016E6F
45constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
46constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
47constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
48
69class OverworldExit : public GameEntity {
70 public:
71 uint16_t y_scroll_;
72 uint16_t x_scroll_;
73 uint16_t y_player_; // Player spawn Y (0-4088 range, ZScream: PlayerY)
74 uint16_t x_player_; // Player spawn X (0-4088 range, ZScream: PlayerX)
75 uint16_t y_camera_; // Camera Y position
76 uint16_t x_camera_; // Camera X position
79 uint16_t door_type_1_;
80 uint16_t door_type_2_;
81 uint16_t room_id_; // ZScream: RoomID
82 uint16_t map_pos_; // VRAM location (ZScream: VRAMLocation)
83 bool is_hole_ = false;
84 bool deleted_ = false;
86 true; // FIX: Default to true (matches ZScream ExitOW.cs:101)
87
88 OverworldExit() = default;
89
98 OverworldExit(uint16_t room_id, uint8_t map_id, uint16_t vram_location,
99 uint16_t y_scroll, uint16_t x_scroll, uint16_t player_y,
100 uint16_t player_x, uint16_t camera_y, uint16_t camera_x,
101 uint8_t scroll_mod_y, uint8_t scroll_mod_x,
102 uint16_t door_type_1, uint16_t door_type_2,
103 bool deleted = false)
104 : y_scroll_(y_scroll),
105 x_scroll_(x_scroll),
106 y_player_(player_y),
107 x_player_(player_x),
108 y_camera_(camera_y),
109 x_camera_(camera_x),
110 scroll_mod_y_(scroll_mod_y),
111 scroll_mod_x_(scroll_mod_x),
112 door_type_1_(door_type_1),
113 door_type_2_(door_type_2),
114 room_id_(room_id),
115 map_pos_(vram_location),
116 is_hole_(false),
117 deleted_(deleted) {
118 // Initialize base entity fields (ZScream: PlayerX/PlayerY → x_/y_)
119 x_ = player_x;
120 y_ = player_y;
121 map_id_ = map_id; // FIX Bug 1: Store original map_id WITHOUT modification
123
124 // Calculate game coordinates using normalized map_id (0-63 range)
125 // ZScream: ExitOW.cs:159-163
126 uint8_t normalized_map_id = map_id % 0x40;
127 int mapX = normalized_map_id % 8;
128 int mapY = normalized_map_id / 8;
129
130 // FIX Bug 4: Calculate game coords ONCE using correct formula
131 // ZScream: ExitOW.cs:162-163 (AreaX/AreaY)
132 game_x_ = static_cast<int>((std::abs(x_ - (mapX * 512)) / 16));
133 game_y_ = static_cast<int>((std::abs(y_ - (mapY * 512)) / 16));
134
135 // Door position calculations (used by door editor, not for coordinates)
136 // ZScream: ExitOW.cs:145-157
137 // These update DoorXEditor/DoorYEditor, NOT AreaX/AreaY
138 }
139
154 void UpdateMapProperties(uint16_t map_id, const void* context) override;
155};
156
157absl::StatusOr<std::vector<OverworldExit>> LoadExits(Rom* rom);
158absl::Status SaveExits(Rom* rom, const std::vector<OverworldExit>& exits);
159
160} // namespace yaze::zelda3
161
162#endif // YAZE_APP_ZELDA3_OVERWORLD_EXIT_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
Base class for all overworld and dungeon entities.
Definition common.h:31
enum yaze::zelda3::GameEntity::EntityType entity_type_
Represents an overworld exit that transitions from dungeon to overworld.
void UpdateMapProperties(uint16_t map_id, const void *context) override
Update exit properties when moved or map changes.
OverworldExit(uint16_t room_id, uint8_t map_id, uint16_t vram_location, uint16_t y_scroll, uint16_t x_scroll, uint16_t player_y, uint16_t player_x, uint16_t camera_y, uint16_t camera_x, uint8_t scroll_mod_y, uint8_t scroll_mod_x, uint16_t door_type_1, uint16_t door_type_2, bool deleted=false)
Constructor for loading exits from ROM.
Zelda 3 specific classes and functions.
Definition editor.h:35
constexpr int OWExitYScroll
constexpr int OWWhirlpoolPosition
constexpr int OWExitXCameraWhirlpool
constexpr int OWExitDoorType2
constexpr int OWExitYScrollWhirlpool
constexpr int OWExitYCamera
constexpr int OWExitDoorPosition
constexpr int OWExitYCameraWhirlpool
constexpr int OWExitXScroll
constexpr int OWExitRoomId
constexpr int OWExitXCamera
constexpr int OWExitUnk1
constexpr int OWExitYPlayer
constexpr int OWExitVramWhirlpool
absl::StatusOr< std::vector< OverworldExit > > LoadExits(Rom *rom)
constexpr int OWExitMapIdWhirlpool
constexpr int OWExitMapId
constexpr int OWExitUnk2
constexpr int OWExitUnk1Whirlpool
constexpr int OWExitDoorType1
constexpr int kNumOverworldExits
constexpr int OWExitXPlayerWhirlpool
constexpr int OWExitUnk2Whirlpool
constexpr int OWExitYPlayerWhirlpool
absl::Status SaveExits(Rom *rom, const std::vector< OverworldExit > &exits)
constexpr int OWExitXPlayer
constexpr int OWExitVram
constexpr int OWExitXScrollWhirlpool