OverworldEntity update: Entrances, Exits, Items

This commit is contained in:
scawful
2024-01-27 15:55:47 -05:00
parent c4a44fbc10
commit e086f12ade
19 changed files with 1009 additions and 384 deletions

View File

@@ -21,6 +21,143 @@ namespace yaze {
namespace app {
namespace zelda3 {
class OverworldEntity {
public:
enum EntityType {
kEntrance = 0,
kExit = 1,
kItem = 2,
kSprite = 3,
kTransport = 4,
kMusic = 5,
kTilemap = 6,
kProperties = 7
} type_;
int x_;
int y_;
int game_x_;
int game_y_;
int entity_id_;
int map_id_;
auto set_x(int x) { x_ = x; }
auto set_y(int y) { y_ = y; }
OverworldEntity() = default;
virtual void UpdateMapProperties(short map_id) = 0;
};
// List of secret item names
const std::vector<std::string> kSecretItemNames = {
"Nothing", // 0
"Green Rupee", // 1
"Rock hoarder", // 2
"Bee", // 3
"Health pack", // 4
"Bomb", // 5
"Heart ", // 6
"Blue Rupee", // 7
"Key", // 8
"Arrow", // 9
"Bomb", // 10
"Heart", // 11
"Magic", // 12
"Full Magic", // 13
"Cucco", // 14
"Green Soldier", // 15
"Bush Stal", // 16
"Blue Soldier", // 17
"Landmine", // 18
"Heart", // 19
"Fairy", // 20
"Heart", // 21
"Nothing ", // 22
"Hole", // 23
"Warp", // 24
"Staircase", // 25
"Bombable", // 26
"Switch" // 27
};
constexpr int overworldItemsPointers = 0xDC2F9;
constexpr int overworldItemsAddress = 0xDC8B9; // 1BC2F9
constexpr int overworldItemsBank = 0xDC8BF;
constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
class OverworldItem : public OverworldEntity {
public:
bool bg2 = false;
uint8_t game_x;
uint8_t game_y;
uint8_t id;
uint16_t room_map_id;
int unique_id = 0;
bool deleted = false;
OverworldItem() = default;
/// <summary>
/// Initializes a new instance of the <see cref="OverworldItem"/>
/// class.
/// </summary>
/// <param name="id"> The ID. </param>
/// <param name="room_map_id"> The dungeon room ID or overworld area ID.
/// </param> <param name="x"> The in editor X position. </param> <param
/// name="y"> The in editor Y position. </param> <param name="bg2"> Whether
/// the Item is on BG2 or not. </param>
OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2) {
this->id = id;
this->x_ = x;
this->y_ = y;
this->bg2 = bg2;
this->room_map_id = room_map_id;
this->map_id_ = room_map_id;
this->entity_id_ = id;
this->type_ = kItem;
int map_x = room_map_id - ((room_map_id / 8) * 8);
int map_y = room_map_id / 8;
this->game_x = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
this->game_y = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
// this->unique_id = ROM.unique_item_id++;
}
/// <summary>
/// Updates the item info when needed. Generally when moving items around
/// in editor.
/// </summary>
/// <param name="room_map_id"> The dungeon room ID or overworld area ID where
/// the item was moved to. </param>
void UpdateMapProperties(int16_t room_map_id) override {
this->room_map_id = static_cast<uint16_t>(room_map_id);
if (room_map_id >= 64) {
room_map_id -= 64;
}
int map_x = room_map_id - ((room_map_id / 8) * 8);
int map_y = room_map_id / 8;
this->game_x =
static_cast<uint8_t>(std::abs(this->x_ - (map_x * 512)) / 16);
this->game_y =
static_cast<uint8_t>(std::abs(this->y_ - (map_y * 512)) / 16);
std::cout << "Item: " << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(this->id) << " MapId: " << std::hex
<< std::setw(2) << std::setfill('0')
<< static_cast<int>(this->room_map_id)
<< " X: " << static_cast<int>(this->game_x)
<< " Y: " << static_cast<int>(this->game_y) << std::endl;
}
OverworldItem Copy() {
return OverworldItem(this->id, this->room_map_id, this->x_, this->y_,
this->bg2);
}
};
constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences
// 105C2 Ending maps
// 105E2 Sprite Group Table for Ending
@@ -50,10 +187,8 @@ constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
class OverworldExit {
class OverworldExit : public OverworldEntity {
public:
int x_;
int y_;
ushort y_scroll_;
ushort x_scroll_;
uchar y_player_;
@@ -69,23 +204,21 @@ class OverworldExit {
uchar entrance_id_;
uchar area_x_;
uchar area_y_;
short map_id_;
bool is_hole_ = false;
bool deleted = false;
bool is_automatic_ = false;
bool large_map_ = false;
OverworldExit() = default;
OverworldExit(ushort room_id, uchar map_id, ushort vram_location,
ushort y_scroll, ushort x_scroll, ushort player_y,
ushort player_x, ushort camera_y, ushort camera_x,
uchar scroll_mod_y, uchar scroll_mod_x, ushort door_type_1,
ushort door_type_2)
: x_(player_x),
y_(player_y),
map_pos_(vram_location),
: map_pos_(vram_location),
entrance_id_(0),
area_x_(0),
area_y_(0),
map_id_(map_id),
is_hole_(false),
room_id_(room_id),
y_scroll_(y_scroll),
@@ -98,6 +231,12 @@ class OverworldExit {
scroll_mod_x_(scroll_mod_x),
door_type_1_(door_type_1),
door_type_2_(door_type_2) {
// Initialize entity variables
this->x_ = player_x;
this->y_ = player_y;
this->map_id_ = map_id;
this->type_ = kExit;
int mapX = (map_id_ - ((map_id_ / 8) * 8));
int mapY = (map_id_ / 8);
@@ -130,14 +269,14 @@ class OverworldExit {
}
// Overworld overworld
void UpdateMapProperties(uchar map_id, bool large_map = false) {
void UpdateMapProperties(short map_id) override {
map_id_ = map_id;
int large = 256;
int mapid = map_id;
if (map_id < 128) {
large = large_map ? 768 : 256;
large = large_map_ ? 768 : 256;
// if (overworld.overworld_map(map_id)->Parent() != map_id) {
// mapid = overworld.overworld_map(map_id)->Parent();
// }
@@ -223,29 +362,27 @@ constexpr int OWHoleArea = 0xDB826;
//(0x13 entries, 1 byte each) corresponding entrance numbers
constexpr int OWHoleEntrance = 0xDB84C;
class OverworldEntrance {
class OverworldEntrance : public OverworldEntity {
public:
int x_;
int y_;
ushort map_pos_;
uchar entrance_id_;
uchar area_x_;
uchar area_y_;
short map_id_;
bool is_hole_ = false;
bool deleted = false;
OverworldEntrance() = default;
OverworldEntrance(int x, int y, uchar entrance_id, short map_id,
ushort map_pos, bool hole)
: x_(x),
y_(y),
map_pos_(map_pos),
entrance_id_(entrance_id),
map_id_(map_id),
is_hole_(hole) {
: map_pos_(map_pos), entrance_id_(entrance_id), is_hole_(hole) {
x_ = x;
y_ = y;
map_id_ = map_id;
entity_id_ = entrance_id;
type_ = kEntrance;
int mapX = (map_id_ - ((map_id_ / 8) * 8));
int mapY = (map_id_ / 8);
area_x_ = (uchar)((std::abs(x - (mapX * 512)) / 16));
area_y_ = (uchar)((std::abs(y - (mapY * 512)) / 16));
}
@@ -255,7 +392,7 @@ class OverworldEntrance {
is_hole_);
}
void UpdateMapProperties(short map_id) {
void UpdateMapProperties(short map_id) override {
map_id_ = map_id;
if (map_id_ >= 64) {
@@ -289,10 +426,6 @@ constexpr int overworldSpecialPALGroup = 0x16831;
constexpr int overworldSpritesBegining = 0x4C881;
constexpr int overworldSpritesAgahnim = 0x4CA21;
constexpr int overworldSpritesZelda = 0x4C901;
constexpr int overworldItemsPointers = 0xDC2F9;
constexpr int overworldItemsAddress = 0xDC8B9; // 1BC2F9
constexpr int overworldItemsBank = 0xDC8BF;
constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
constexpr int mapGfx = 0x7C9C;
constexpr int overlayPointers = 0x77664;
constexpr int overlayPointersBank = 0x0E;
@@ -353,6 +486,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
absl::Status SaveLargeMaps();
absl::Status SaveEntrances();
absl::Status SaveExits();
absl::Status SaveItems();
bool CreateTile32Tilemap(bool onlyShow = false);
absl::Status SaveMap16Tiles();
@@ -368,10 +502,14 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
std::vector<gfx::Tile16> tiles16() const { return tiles16_; }
auto Sprites(int state) const { return all_sprites_[state]; }
auto mutable_sprites(int state) { return &all_sprites_[state]; }
auto AreaGraphics() const {
return overworld_maps_[current_map_].AreaGraphics();
}
auto &Entrances() { return all_entrances_; }
auto mutable_entrances() { return &all_entrances_; }
auto &holes() { return all_holes_; }
auto mutable_holes() { return &all_holes_; }
auto AreaPalette() const {
return overworld_maps_[current_map_].AreaPalette();
}
@@ -387,6 +525,9 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
auto map_tiles() const { return map_tiles_; }
auto mutable_map_tiles() { return &map_tiles_; }
auto all_items() const { return all_items_; }
auto mutable_all_items() { return &all_items_; }
auto &ref_all_items() { return all_items_; }
absl::Status LoadPrototype(ROM &rom_, const std::string &tilemap_filename);
@@ -410,6 +551,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
void FetchLargeMaps();
void LoadEntrances();
void LoadExits();
absl::Status LoadItems();
void LoadSprites();
void LoadSpritesFromMap(int spriteStart, int spriteCount, int spriteIndex);
@@ -429,6 +571,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
std::vector<OverworldEntrance> all_entrances_;
std::vector<OverworldEntrance> all_holes_;
std::vector<OverworldExit> all_exits_;
std::vector<OverworldItem> all_items_;
std::vector<std::vector<Sprite>> all_sprites_;
std::vector<absl::flat_hash_map<uint16_t, int>> usage_stats_;