yaze 0.2.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 <cstdint>
5#include <iostream>
6
7#include "app/zelda3/common.h"
8#include "util/macro.h"
9
10namespace yaze {
11namespace zelda3 {
12
13constexpr int kNumOverworldExits = 0x4F;
14constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences
15// 105C2 Ending maps
16// 105E2 Sprite Group Table for Ending
17constexpr int OWExitMapId = 0x15E28;
18constexpr int OWExitVram = 0x15E77;
19constexpr int OWExitYScroll = 0x15F15;
20constexpr int OWExitXScroll = 0x15FB3;
21constexpr int OWExitYPlayer = 0x16051;
22constexpr int OWExitXPlayer = 0x160EF;
23constexpr int OWExitYCamera = 0x1618D;
24constexpr int OWExitXCamera = 0x1622B;
25constexpr int OWExitDoorPosition = 0x15724;
26constexpr int OWExitUnk1 = 0x162C9;
27constexpr int OWExitUnk2 = 0x16318;
28constexpr int OWExitDoorType1 = 0x16367;
29constexpr int OWExitDoorType2 = 0x16405;
30
31constexpr int OWExitMapIdWhirlpool = 0x16AE5; // JP = ;016849
32constexpr int OWExitVramWhirlpool = 0x16B07; // JP = ;01686B
33constexpr int OWExitYScrollWhirlpool = 0x16B29; // JP = ;01688D
34constexpr int OWExitXScrollWhirlpool = 0x16B4B; // JP = ;016DE7
35constexpr int OWExitYPlayerWhirlpool = 0x16B6D; // JP = ;016E09
36constexpr int OWExitXPlayerWhirlpool = 0x16B8F; // JP = ;016E2B
37constexpr int OWExitYCameraWhirlpool = 0x16BB1; // JP = ;016E4D
38constexpr int OWExitXCameraWhirlpool = 0x16BD3; // JP = ;016E6F
39constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
40constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
41constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
42
43class OverworldExit : public GameEntity {
44 public:
45 uint16_t y_scroll_;
46 uint16_t x_scroll_;
47 uint8_t y_player_;
48 uint8_t x_player_;
49 uint8_t y_camera_;
50 uint8_t x_camera_;
53 uint16_t door_type_1_;
54 uint16_t door_type_2_;
55 uint16_t room_id_;
56 uint16_t map_pos_; // Position in the vram
57 uint8_t entrance_id_;
58 uint8_t area_x_;
59 uint8_t area_y_;
60 bool is_hole_ = false;
61 bool deleted_ = false;
62 bool is_automatic_ = false;
63 bool large_map_ = false;
64
65 OverworldExit() = default;
66 OverworldExit(uint16_t room_id, uint8_t map_id, uint16_t vram_location,
67 uint16_t y_scroll, uint16_t x_scroll, uint16_t player_y,
68 uint16_t player_x, uint16_t camera_y, uint16_t camera_x,
69 uint8_t scroll_mod_y, uint8_t scroll_mod_x,
70 uint16_t door_type_1, uint16_t door_type_2,
71 bool deleted = false)
72 : map_pos_(vram_location),
73 entrance_id_(0),
74 area_x_(0),
75 area_y_(0),
76 room_id_(room_id),
77 y_scroll_(y_scroll),
78 x_scroll_(x_scroll),
79 y_player_(player_y),
80 x_player_(player_x),
81 y_camera_(camera_y),
82 x_camera_(camera_x),
83 scroll_mod_y_(scroll_mod_y),
84 scroll_mod_x_(scroll_mod_x),
85 door_type_1_(door_type_1),
86 door_type_2_(door_type_2),
87 is_hole_(false),
88 deleted_(deleted) {
89 // Initialize entity variables
90 x_ = player_x;
91 y_ = player_y;
92 map_id_ = map_id;
94
95 int mapX = (map_id_ - ((map_id_ / 8) * 8));
96 int mapY = (map_id_ / 8);
97
98 area_x_ = (uint8_t)((std::abs(x_ - (mapX * 512)) / 16));
99 area_y_ = (uint8_t)((std::abs(y_ - (mapY * 512)) / 16));
100
101 if (door_type_1 != 0) {
102 int p = (door_type_1 & 0x7FFF) >> 1;
103 entrance_id_ = (uint8_t)(p % 64);
104 area_y_ = (uint8_t)(p >> 6);
105 }
106
107 if (door_type_2 != 0) {
108 int p = (door_type_2 & 0x7FFF) >> 1;
109 entrance_id_ = (uint8_t)(p % 64);
110 area_y_ = (uint8_t)(p >> 6);
111 }
112
113 if (map_id_ >= 64) {
114 map_id_ -= 64;
115 }
116
117 mapX = (map_id_ - ((map_id_ / 8) * 8));
118 mapY = (map_id_ / 8);
119
120 area_x_ = (uint8_t)((std::abs(x_ - (mapX * 512)) / 16));
121 area_y_ = (uint8_t)((std::abs(y_ - (mapY * 512)) / 16));
122
123 map_pos_ = (uint16_t)((((area_y_) << 6) | (area_x_ & 0x3F)) << 1);
124 }
125
126 // Overworld overworld
127 void UpdateMapProperties(uint16_t map_id) override {
128 map_id_ = map_id;
129
130 int large = 256;
131 int mapid = map_id;
132
133 if (map_id < 128) {
134 large = large_map_ ? 768 : 256;
135 // if (overworld.overworld_map(map_id)->Parent() != map_id) {
136 // mapid = overworld.overworld_map(map_id)->Parent();
137 // }
138 }
139
140 int mapX = map_id - ((map_id / 8) * 8);
141 int mapY = map_id / 8;
142
143 area_x_ = (uint8_t)((std::abs(x_ - (mapX * 512)) / 16));
144 area_y_ = (uint8_t)((std::abs(y_ - (mapY * 512)) / 16));
145
146 if (map_id >= 64) {
147 map_id -= 64;
148 }
149
150 int mapx = (map_id & 7) << 9;
151 int mapy = (map_id & 56) << 6;
152
153 if (is_automatic_) {
154 x_ = x_ - 120;
155 y_ = y_ - 80;
156
157 if (x_ < mapx) {
158 x_ = mapx;
159 }
160
161 if (y_ < mapy) {
162 y_ = mapy;
163 }
164
165 if (x_ > mapx + large) {
166 x_ = mapx + large;
167 }
168
169 if (y_ > mapy + large + 32) {
170 y_ = mapy + large + 32;
171 }
172
173 x_camera_ = x_player_ + 0x07;
174 y_camera_ = y_player_ + 0x1F;
175
176 if (x_camera_ < mapx + 127) {
177 x_camera_ = mapx + 127;
178 }
179
180 if (y_camera_ < mapy + 111) {
181 y_camera_ = mapy + 111;
182 }
183
184 if (x_camera_ > mapx + 127 + large) {
185 x_camera_ = mapx + 127 + large;
186 }
187
188 if (y_camera_ > mapy + 143 + large) {
189 y_camera_ = mapy + 143 + large;
190 }
191 }
192
193 short vram_x_scroll = (short)(x_ - mapx);
194 short vram_y_scroll = (short)(y_ - mapy);
195
196 map_pos_ = (uint16_t)(((vram_y_scroll & 0xFFF0) << 3) |
197 ((vram_x_scroll & 0xFFF0) >> 3));
198
199 std::cout << "Exit: " << room_id_ << " MapId: " << std::hex << mapid
200 << " X: " << static_cast<int>(area_x_)
201 << " Y: " << static_cast<int>(area_y_) << std::endl;
202 }
203};
204
205} // namespace zelda3
206} // namespace yaze
207
208#endif // YAZE_APP_ZELDA3_OVERWORLD_EXIT_H_
enum yaze::zelda3::GameEntity::EntityType entity_type_
void UpdateMapProperties(uint16_t map_id) override
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)
Zelda 3 specific classes and functions.
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
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
constexpr int OWExitXPlayer
constexpr int OWExitVram
constexpr int OWExitXScrollWhirlpool
Main namespace for the application.
Definition controller.cc:18