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 "app/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;
49 entity_id_ = id;
51
52 int map_x = room_map_id - ((room_map_id / 8) * 8);
53 int map_y = room_map_id / 8;
54
55 game_x_ = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
56 game_y_ = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
57 }
58
59 void UpdateMapProperties(uint16_t room_map_id) override {
60 room_map_id_ = room_map_id;
61
62 if (room_map_id_ >= 64) {
63 room_map_id_ -= 64;
64 }
65
66 int map_x = room_map_id_ - ((room_map_id_ / 8) * 8);
67 int map_y = room_map_id_ / 8;
68
69 game_x_ = static_cast<uint8_t>(std::abs(x_ - (map_x * 512)) / 16);
70 game_y_ = static_cast<uint8_t>(std::abs(y_ - (map_y * 512)) / 16);
71 }
72
73 bool bg2_ = false;
74 uint8_t id_;
75 uint8_t game_x_;
76 uint8_t game_y_;
77 uint16_t room_map_id_;
78 int unique_id = 0;
79 bool deleted = false;
80};
81
82inline bool CompareOverworldItems(const std::vector<OverworldItem>& items1,
83 const std::vector<OverworldItem>& items2) {
84 if (items1.size() != items2.size()) {
85 return false;
86 }
87
88 const auto is_same_item = [](const OverworldItem& a, const OverworldItem& b) {
89 return a.x_ == b.x_ && a.y_ == b.y_ && a.id_ == b.id_;
90 };
91
92 return std::all_of(items1.begin(), items1.end(),
93 [&](const OverworldItem& it) {
94 return std::any_of(items2.begin(), items2.end(),
95 [&](const OverworldItem& other) {
96 return is_same_item(it, other);
97 });
98 });
99}
100
101inline bool CompareItemsArrays(std::vector<OverworldItem> item_array1,
102 std::vector<OverworldItem> item_array2) {
103 if (item_array1.size() != item_array2.size()) {
104 return false;
105 }
106
107 bool match;
108 for (size_t i = 0; i < item_array1.size(); i++) {
109 match = false;
110 for (size_t j = 0; j < item_array2.size(); j++) {
111 // Check all sprite in 2nd array if one match
112 if (item_array1[i].x_ == item_array2[j].x_ &&
113 item_array1[i].y_ == item_array2[j].y_ &&
114 item_array1[i].id_ == item_array2[j].id_) {
115 match = true;
116 break;
117 }
118 }
119
120 if (!match) {
121 return false;
122 }
123 }
124
125 return true;
126}
127
128absl::StatusOr<std::vector<OverworldItem>> LoadItems(Rom* rom, std::vector<OverworldMap>& overworld_maps);
129absl::Status SaveItems(Rom* rom, const std::vector<OverworldItem>& items);
130
131const std::vector<std::string> kSecretItemNames = {
132 "Nothing", // 0
133 "Green Rupee", // 1
134 "Rock hoarder", // 2
135 "Bee", // 3
136 "Health pack", // 4
137 "Bomb", // 5
138 "Heart ", // 6
139 "Blue Rupee", // 7
140 "Key", // 8
141 "Arrow", // 9
142 "Bomb", // 10
143 "Heart", // 11
144 "Magic", // 12
145 "Full Magic", // 13
146 "Cucco", // 14
147 "Green Soldier", // 15
148 "Bush Stal", // 16
149 "Blue Soldier", // 17
150 "Landmine", // 18
151 "Heart", // 19
152 "Fairy", // 20
153 "Heart", // 21
154 "Nothing ", // 22
155 "Hole", // 23
156 "Warp", // 24
157 "Staircase", // 25
158 "Bombable", // 26
159 "Switch" // 27
160};
161
162} // namespace zelda3
163} // namespace yaze
164
165#endif // YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
Base class for all overworld and dungeon entities.
Definition common.h:17
enum yaze::zelda3::GameEntity::EntityType entity_type_
void UpdateMapProperties(uint16_t room_map_id) override
OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2)
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
Main namespace for the application.
Definition controller.cc:20