Add DrawOverworldExits and DrawOverworldProperties

This commit is contained in:
scawful
2024-01-10 23:12:54 -05:00
parent 27098a7917
commit 781f15bb81
5 changed files with 278 additions and 18 deletions

View File

@@ -10,8 +10,8 @@
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "app/core/constants.h"
#include "app/core/common.h"
#include "app/core/constants.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/compression.h"
#include "app/gfx/snes_tile.h"
@@ -140,6 +140,7 @@ absl::Status Overworld::Load(ROM &rom) {
FetchLargeMaps();
LoadEntrances();
LoadExits();
RETURN_IF_ERROR(LoadOverworldMaps())
if (flags()->kDrawOverworldSprites) {
LoadSprites();
@@ -893,6 +894,60 @@ void Overworld::LoadEntrances() {
}
}
void Overworld::LoadExits() {
const int NumberOfOverworldExits = 0x4F;
std::vector<OverworldExit> exits;
for (int i = 0; i < NumberOfOverworldExits; i++) {
auto rom_data = rom()->data();
ushort exitRoomID = (ushort)((rom_data[OWExitRoomId + (i * 2) + 1] << 8) +
rom_data[OWExitRoomId + (i * 2)]);
ushort exitMapID = rom_data[OWExitMapId + i];
ushort exitVRAM = (ushort)((rom_data[OWExitVram + (i * 2) + 1] << 8) +
rom_data[OWExitVram + (i * 2)]);
ushort exitYScroll = (ushort)((rom_data[OWExitYScroll + (i * 2) + 1] << 8) +
rom_data[OWExitYScroll + (i * 2)]);
ushort exitXScroll = (ushort)((rom_data[OWExitXScroll + (i * 2) + 1] << 8) +
rom_data[OWExitXScroll + (i * 2)]);
ushort py = (ushort)((rom_data[OWExitYPlayer + (i * 2) + 1] << 8) +
rom_data[OWExitYPlayer + (i * 2)]);
ushort px = (ushort)((rom_data[OWExitXPlayer + (i * 2) + 1] << 8) +
rom_data[OWExitXPlayer + (i * 2)]);
ushort exitYCamera = (ushort)((rom_data[OWExitYCamera + (i * 2) + 1] << 8) +
rom_data[OWExitYCamera + (i * 2)]);
ushort exitXCamera = (ushort)((rom_data[OWExitXCamera + (i * 2) + 1] << 8) +
rom_data[OWExitXCamera + (i * 2)]);
ushort exitScrollModY = rom_data[OWExitUnk1 + i];
ushort exitScrollModX = rom_data[OWExitUnk2 + i];
ushort exitDoorType1 =
(ushort)((rom_data[OWExitDoorType1 + (i * 2) + 1] << 8) +
rom_data[OWExitDoorType1 + (i * 2)]);
ushort exitDoorType2 =
(ushort)((rom_data[OWExitDoorType2 + (i * 2) + 1] << 8) +
rom_data[OWExitDoorType2 + (i * 2)]);
OverworldExit exit(exitRoomID, exitMapID, exitVRAM, exitYScroll,
exitXScroll, py, px, exitYCamera, exitXCamera,
exitScrollModY, exitScrollModX, exitDoorType1,
exitDoorType2);
std::cout << "Exit: " << i << " RoomID: " << exitRoomID
<< " MapID: " << exitMapID << " VRAM: " << exitVRAM
<< " YScroll: " << exitYScroll << " XScroll: " << exitXScroll
<< " YPlayer: " << py << " XPlayer: " << px
<< " YCamera: " << exitYCamera << " XCamera: " << exitXCamera
<< " ScrollModY: " << exitScrollModY
<< " ScrollModX: " << exitScrollModX
<< " DoorType1: " << exitDoorType1
<< " DoorType2: " << exitDoorType2 << std::endl;
if (px == 0xFFFF && py == 0xFFFF) {
exit.deleted = true;
}
exits.push_back(exit);
}
all_exits_ = exits;
}
void Overworld::LoadSprites() {
for (int i = 0; i < 3; i++) {
all_sprites_.emplace_back();

View File

@@ -60,6 +60,141 @@ constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
class OverworldExit {
public:
int x_;
int y_;
ushort room_id_;
ushort map_pos_;
uchar entrance_id_;
uchar area_x_;
uchar area_y_;
short map_id_;
bool is_hole_ = false;
bool deleted = false;
OverworldExit(ushort roomID, uchar mapID, ushort vramLocation, ushort yScroll,
ushort xScroll, ushort playerY, ushort playerX, ushort cameraY,
ushort cameraX, uchar scrollModY, uchar scrollModX,
ushort doorType1, ushort doorType2)
: x_(playerX),
y_(playerY),
map_pos_(vramLocation),
entrance_id_(0),
area_x_(0),
area_y_(0),
map_id_(mapID),
is_hole_(false) {
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));
if (doorType1 != 0) {
int p = (doorType1 & 0x7FFF) >> 1;
entrance_id_ = (uchar)(p % 64);
area_y_ = (uchar)(p >> 6);
}
if (doorType2 != 0) {
int p = (doorType2 & 0x7FFF) >> 1;
entrance_id_ = (uchar)(p % 64);
area_y_ = (uchar)(p >> 6);
}
if (map_id_ >= 64) {
map_id_ -= 64;
}
mapX = (map_id_ - ((map_id_ / 8) * 8));
mapY = (map_id_ / 8);
area_x_ = (uchar)((std::abs(x_ - (mapX * 512)) / 16));
area_y_ = (uchar)((std::abs(y_ - (mapY * 512)) / 16));
map_pos_ = (ushort)((((area_y_) << 6) | (area_x_ & 0x3F)) << 1);
}
// void updateMapStuff(uchar mapID, Overworld overworld) {
// map_id_ = mapID;
// int large = 256;
// int mapid = mapID;
// if (mapID < 128) {
// large = overworld.AllMaps[mapID].LargeMap ? 768 : 256;
// if (overworld.AllMaps[mapID].ParentID != mapID) {
// mapid = overworld.AllMaps[mapID].ParentID;
// }
// }
// int mapX = mapID - ((mapID / 8) * 8);
// int mapY = mapID / 8;
// area_x_ = (uchar)((std::abs(x_ - (mapX * 512)) / 16));
// area_y_ = (uchar)((std::abs(y_ - (mapY * 512)) / 16));
// if (mapID >= 64) {
// mapID -= 64;
// }
// int mapx = (mapID & 7) << 9;
// int mapy = (mapID & 56) << 6;
// if (IsAutomatic) {
// x_ = x_ - 120;
// y_ = y_ - 80;
// if (x_ < mapx) {
// x_ = mapx;
// }
// if (y_ < mapy) {
// y_ = mapy;
// }
// if (x_ > mapx + large) {
// x_ = mapx + large;
// }
// if (y_ > mapy + large + 32) {
// y_ = mapy + large + 32;
// }
// cameraX = playerX + 0x07;
// cameraY = playerY + 0x1F;
// if (cameraX < mapx + 127) {
// cameraX = mapx + 127;
// }
// if (cameraY < mapy + 111) {
// cameraY = mapy + 111;
// }
// if (cameraX > mapx + 127 + large) {
// cameraX = mapx + 127 + large;
// }
// if (cameraY > mapy + 143 + large) {
// cameraY = mapy + 143 + large;
// }
// }
// short vramXScroll = (short)(x_ - mapx);
// short vramYScroll = (short)(y_ - mapy);
// map_pos_ =
// (ushort)(((vramYScroll & 0xFFF0) << 3) | ((vramXScroll & 0xFFF0) >>
// 3));
// std::cout << "Exit: " << room_id_ << " MapId: " << std::hex << mapid
// << " X: " << static_cast<int>(area_x_)
// << " Y: " << static_cast<int>(area_y_) << std::endl;
// }
};
class OverworldEntrance {
public:
int x_;
@@ -199,6 +334,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
return overworld_maps_[current_map_].AreaGraphics();
}
auto &Entrances() { return all_entrances_; }
auto &Exits() { return all_exits_; }
auto AreaPalette() const {
return overworld_maps_[current_map_].AreaPalette();
}
@@ -236,6 +372,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
absl::Status DecompressProtoMapTiles(const std::string &filename);
void FetchLargeMaps();
void LoadEntrances();
void LoadExits();
void LoadSprites();
void LoadSpritesFromMap(int spriteStart, int spriteCount, int spriteIndex);
@@ -253,6 +390,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
std::vector<OverworldMap> overworld_maps_;
std::vector<OverworldEntrance> all_entrances_;
std::vector<OverworldEntrance> all_holes_;
std::vector<OverworldExit> all_exits_;
std::vector<std::vector<Sprite>> all_sprites_;
absl::flat_hash_map<int, MapData> proto_map_data_;

View File

@@ -39,6 +39,12 @@ class OverworldMap {
auto IsInitialized() const { return initialized_; }
auto Parent() const { return parent_; }
auto area_graphics() const { return area_graphics_; }
auto area_palette() const { return area_palette_; }
auto sprite_graphics(int i) const { return sprite_graphics_[i]; }
auto sprite_palette(int i) const { return sprite_palette_[i]; }
auto message_id() const { return message_id_; }
auto mutable_area_graphics() { return &area_graphics_; }
auto mutable_area_palette() { return &area_palette_; }
auto mutable_sprite_graphics(int i) { return &sprite_graphics_[i]; }