yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_item.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
2#define YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
3
4#include <algorithm>
5#include <cstdint>
6#include <iomanip>
7#include <iostream>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "rom/rom.h"
14#include "zelda3/common.h"
15
16namespace yaze {
17namespace zelda3 {
18
19// Forward declaration of OverworldMap class
20class OverworldMap;
21
22constexpr int kNumOverworldMapItemPointers = 0x80;
23constexpr int kOverworldItemsPointers = 0xDC2F9;
24constexpr int kOverworldItemsAddress = 0xDC8B9; // 1BC2F9
25constexpr int kOverworldItemsBank = 0xDC8BF;
26constexpr int kOverworldItemsEndData = 0xDC89C; // 0DC89E
27
28constexpr int kOverworldBombDoorItemLocationsNew = 0x012644;
29constexpr int kOverworldItemsPointersNew = 0x012784;
30constexpr int kOverworldItemsStartDataNew = 0x0DC2F9;
31
32constexpr int overworldItemsPointers = 0x0DC2F9;
33constexpr int overworldItemsAddress = 0x0DC8B9; // 1BC2F9
34constexpr int overworldItemsAddressBank = 0x0DC8BF;
35constexpr int overworldItemsEndData = 0x0DC89C; // 0DC89E
36
37constexpr int overworldBombDoorItemLocationsNew = 0x012644;
38constexpr int overworldItemsPointersNew = 0x012784;
39constexpr int overworldItemsStartDataNew = 0x0DC2F9;
40
41class OverworldItem : public GameEntity {
42 public:
43 OverworldItem() = default;
44 OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2)
45 : bg2_(bg2), id_(id), room_map_id_(room_map_id) {
46 x_ = x;
47 y_ = y;
48 map_id_ = room_map_id; // Store original map_id
49 entity_id_ = id;
51
52 // Use normalized map_id for coordinate calculations
53 uint8_t normalized_map_id = room_map_id % 0x40;
54 int map_x = normalized_map_id % 8;
55 int map_y = normalized_map_id / 8;
56
57 game_x_ = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
58 game_y_ = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
59 }
60
61 void UpdateMapProperties(uint16_t room_map_id,
62 const void* context = nullptr) override {
63 (void)context; // Not used by items currently
64 room_map_id_ = room_map_id;
65
66 // Use normalized map_id for calculations (don't corrupt stored value)
67 uint8_t normalized_map_id = room_map_id % 0x40;
68 int map_x = normalized_map_id % 8;
69 int map_y = normalized_map_id / 8;
70
71 // Update game coordinates from world coordinates
72 game_x_ = static_cast<uint8_t>(std::abs(x_ - (map_x * 512)) / 16);
73 game_y_ = static_cast<uint8_t>(std::abs(y_ - (map_y * 512)) / 16);
74 }
75
76 bool bg2_ = false;
77 uint8_t id_;
78 uint8_t game_x_;
79 uint8_t game_y_;
80 uint16_t room_map_id_;
81 int unique_id = 0;
82 bool deleted = false;
83};
84
85inline bool CompareOverworldItems(const std::vector<OverworldItem>& items1,
86 const std::vector<OverworldItem>& items2) {
87 if (items1.size() != items2.size()) {
88 return false;
89 }
90
91 const auto is_same_item = [](const OverworldItem& a, const OverworldItem& b) {
92 return a.x_ == b.x_ && a.y_ == b.y_ && a.id_ == b.id_;
93 };
94
95 return std::all_of(items1.begin(), items1.end(),
96 [&](const OverworldItem& it) {
97 return std::any_of(items2.begin(), items2.end(),
98 [&](const OverworldItem& other) {
99 return is_same_item(it, other);
100 });
101 });
102}
103
104inline bool CompareItemsArrays(std::vector<OverworldItem> item_array1,
105 std::vector<OverworldItem> item_array2) {
106 if (item_array1.size() != item_array2.size()) {
107 return false;
108 }
109
110 bool match;
111 for (size_t i = 0; i < item_array1.size(); i++) {
112 match = false;
113 for (size_t j = 0; j < item_array2.size(); j++) {
114 // Check all sprite in 2nd array if one match
115 if (item_array1[i].x_ == item_array2[j].x_ &&
116 item_array1[i].y_ == item_array2[j].y_ &&
117 item_array1[i].id_ == item_array2[j].id_) {
118 match = true;
119 break;
120 }
121 }
122
123 if (!match) {
124 return false;
125 }
126 }
127
128 return true;
129}
130
131absl::StatusOr<std::vector<OverworldItem>> LoadItems(
132 Rom* rom, std::vector<OverworldMap>& overworld_maps);
133absl::Status SaveItems(Rom* rom, const std::vector<OverworldItem>& items);
134
135const std::vector<std::string> kSecretItemNames = {
136 "Nothing", // 0
137 "Green Rupee", // 1
138 "Rock hoarder", // 2
139 "Bee", // 3
140 "Health pack", // 4
141 "Bomb", // 5
142 "Heart ", // 6
143 "Blue Rupee", // 7
144 "Key", // 8
145 "Arrow", // 9
146 "Bomb", // 10
147 "Heart", // 11
148 "Magic", // 12
149 "Full Magic", // 13
150 "Cucco", // 14
151 "Green Soldier", // 15
152 "Bush Stal", // 16
153 "Blue Soldier", // 17
154 "Landmine", // 18
155 "Heart", // 19
156 "Fairy", // 20
157 "Heart", // 21
158 "Nothing ", // 22
159 "Hole", // 23
160 "Warp", // 24
161 "Staircase", // 25
162 "Bombable", // 26
163 "Switch" // 27
164};
165
166} // namespace zelda3
167} // namespace yaze
168
169#endif // YAZE_APP_ZELDA3_OVERWORLD_ITEM_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_
OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2)
void UpdateMapProperties(uint16_t room_map_id, const void *context=nullptr) override
Update entity properties based on map position.
constexpr int kOverworldItemsBank
constexpr int overworldItemsPointersNew
bool CompareOverworldItems(const std::vector< OverworldItem > &items1, const std::vector< OverworldItem > &items2)
constexpr int overworldItemsAddressBank
constexpr int kNumOverworldMapItemPointers
constexpr int kOverworldItemsAddress
bool CompareItemsArrays(std::vector< OverworldItem > item_array1, std::vector< OverworldItem > item_array2)
constexpr int kOverworldItemsEndData
const std::vector< std::string > kSecretItemNames
constexpr int kOverworldItemsStartDataNew
constexpr int overworldItemsAddress
constexpr int overworldItemsEndData
constexpr int overworldItemsPointers
constexpr int kOverworldItemsPointers
constexpr int overworldItemsStartDataNew
constexpr int kOverworldBombDoorItemLocationsNew
constexpr int overworldBombDoorItemLocationsNew
constexpr int kOverworldItemsPointersNew