diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2019-01-07 18:39:27 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2019-01-07 18:39:27 -0500 |
commit | f7eef0735bb70a7fed17b6fabb15f30c092209bc (patch) | |
tree | 17f9256f07ff23163cf13af85fdc36847549cbbe /src | |
parent | f50bc217ae5daeb2c2788f502f604e3684249256 (diff) | |
parent | 8f7400809626c0f72dfe751665126f94181fd7c1 (diff) |
Merge branch 'master' into trainer_tower
Diffstat (limited to 'src')
-rw-r--r-- | src/fieldmap.c | 1025 | ||||
-rw-r--r-- | src/quest_log.c | 4 | ||||
-rw-r--r-- | src/save.c | 4 | ||||
-rw-r--r-- | src/scrcmd.c | 2267 | ||||
-rw-r--r-- | src/script.c | 6 | ||||
-rw-r--r-- | src/trainer_tower.c | 8 | ||||
-rw-r--r-- | src/vs_seeker.c | 4 |
7 files changed, 3305 insertions, 13 deletions
diff --git a/src/fieldmap.c b/src/fieldmap.c new file mode 100644 index 000000000..be5e1d54a --- /dev/null +++ b/src/fieldmap.c @@ -0,0 +1,1025 @@ +#include "global.h" +#include "bg.h" +#include "palette.h" +#include "overworld.h" +#include "script.h" +#include "menu.h" +#include "new_menu_helpers.h" +#include "quest_log.h" +#include "fieldmap.h" + +struct ConnectionFlags +{ + u8 south:1; + u8 north:1; + u8 west:1; + u8 east:1; +}; + +void sub_8058A00(struct MapHeader *mapHeader); +void map_copy_with_padding(u16 *map, u16 width, u16 height); +void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader); +void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +void LoadSavedMapView(void); +struct MapConnection *sub_8059600(u8 direction, s32 x, s32 y); +bool8 sub_8059658(u8 direction, s32 x, s32 y, struct MapConnection *connection); +bool8 sub_80596BC(s32 x, s32 src_width, s32 dest_width, s32 offset); + +struct BackupMapData VMap; +EWRAM_DATA u16 gBackupMapData[VIRTUAL_MAP_SIZE] = {}; +EWRAM_DATA struct MapHeader gMapHeader = {}; +EWRAM_DATA struct Camera gCamera = {}; +EWRAM_DATA struct ConnectionFlags gMapConnectionFlags = {}; + +const struct ConnectionFlags sDummyConnectionFlags = {}; + +const u32 gUnknown_8352EF0[] = { + 0x1ff, + 0x3e00, + 0x3c000, + 0xfc0000, + 0x7000000, + 0x18000000, + 0x60000000, + 0x80000000 +}; + +const u8 gUnknown_8352F10[] = { + 0, + 9, + 14, + 18, + 24, + 27, + 29, + 31 +}; + +const struct MapHeader * mapconnection_get_mapheader(struct MapConnection * connection) +{ + return get_mapheader_by_bank_and_number(connection->mapGroup, connection->mapNum); +} + +void not_trainer_hill_battle_pyramid(void) +{ + sub_8058A00(&gMapHeader); + mapheader_run_script_with_tag_x1(); +} + +void sub_80589E8(void) +{ + sub_8058A00(&gMapHeader); + LoadSavedMapView(); + mapheader_run_script_with_tag_x1(); +} + +void sub_8058A00(struct MapHeader * mapHeader) +{ + const struct MapData * mapData = mapHeader->mapData; + CpuFastFill(0x03FF03FF, gBackupMapData, sizeof(gBackupMapData)); + VMap.map = gBackupMapData; + VMap.Xsize = mapData->width + 15; + VMap.Ysize = mapData->height + 14; + AGB_ASSERT_EX(VMap.Xsize * VMap.Ysize <= VIRTUAL_MAP_SIZE, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/fieldmap.c", 158); + map_copy_with_padding(mapData->map, mapData->width, mapData->height); + mapheader_copy_mapdata_of_adjacent_maps(mapHeader); +} + +void map_copy_with_padding(u16 *map, u16 width, u16 height) +{ + s32 y; + u16 *dest = VMap.map; + dest += VMap.Xsize * 7 + 7; + + for (y = 0; y < height; y++) + { + CpuCopy16(map, dest, width * sizeof(u16)); + dest += width + 15; + map += width; + } +} + +void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader) +{ + s32 count; + struct MapConnection *connection; + s32 i; + + gMapConnectionFlags = sDummyConnectionFlags; + + /* + * This null pointer check is new to FireRed. It was kept in + * Emerald, with the above struct assignment moved to after + * this check. + */ + if (mapHeader->connections) + { + count = mapHeader->connections->count; + connection = mapHeader->connections->connections; + // Emerald puts this line here instead: + // gMapConnectionFlags = sDummyConnectionFlags; + for (i = 0; i < count; i++, connection++) + { + struct MapHeader const *cMap = mapconnection_get_mapheader(connection); + u32 offset = connection->offset; + switch (connection->direction) + { + case CONNECTION_SOUTH: + fillSouthConnection(mapHeader, cMap, offset); + gMapConnectionFlags.south = 1; + break; + case CONNECTION_NORTH: + fillNorthConnection(mapHeader, cMap, offset); + gMapConnectionFlags.north = 1; + break; + case CONNECTION_WEST: + fillWestConnection(mapHeader, cMap, offset); + gMapConnectionFlags.west = 1; + break; + case CONNECTION_EAST: + fillEastConnection(mapHeader, cMap, offset); + gMapConnectionFlags.east = 1; + break; + } + } + } +} + +void sub_8058B54(s32 x, s32 y, const struct MapHeader *connectedMapHeader, s32 x2, s32 y2, s32 width, s32 height) +{ + s32 i; + u16 *src; + u16 *dest; + s32 mapWidth; + + mapWidth = connectedMapHeader->mapData->width; + src = &connectedMapHeader->mapData->map[mapWidth * y2 + x2]; + dest = &VMap.map[VMap.Xsize * y + x]; + + for (i = 0; i < height; i++) + { + CpuCopy16(src, dest, width * 2); + dest += VMap.Xsize; + src += mapWidth; + } +} + +void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +{ + s32 x, y; + s32 x2; + s32 width; + s32 cWidth; + + if (connectedMapHeader) + { + cWidth = connectedMapHeader->mapData->width; + x = offset + 7; + y = mapHeader->mapData->height + 7; + if (x < 0) + { + x2 = -x; + x += cWidth; + if (x < VMap.Xsize) + { + width = x; + } + else + { + width = VMap.Xsize; + } + x = 0; + } + else + { + x2 = 0; + if (x + cWidth < VMap.Xsize) + { + width = cWidth; + } + else + { + width = VMap.Xsize - x; + } + } + + sub_8058B54( + x, y, + connectedMapHeader, + x2, /*y2*/ 0, + width, /*height*/ 7); + } +} + +void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +{ + s32 x; + s32 x2, y2; + s32 width; + s32 cWidth, cHeight; + + if (connectedMapHeader) + { + cWidth = connectedMapHeader->mapData->width; + cHeight = connectedMapHeader->mapData->height; + x = offset + 7; + y2 = cHeight - 7; + if (x < 0) + { + x2 = -x; + x += cWidth; + if (x < VMap.Xsize) + { + width = x; + } + else + { + width = VMap.Xsize; + } + x = 0; + } + else + { + x2 = 0; + if (x + cWidth < VMap.Xsize) + { + width = cWidth; + } + else + { + width = VMap.Xsize - x; + } + } + + sub_8058B54( + x, /*y*/ 0, + connectedMapHeader, + x2, y2, + width, /*height*/ 7); + + } +} + +void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +{ + s32 y; + s32 x2, y2; + s32 height; + s32 cWidth, cHeight; + if (connectedMapHeader) + { + cWidth = connectedMapHeader->mapData->width; + cHeight = connectedMapHeader->mapData->height; + y = offset + 7; + x2 = cWidth - 7; + if (y < 0) + { + y2 = -y; + if (y + cHeight < VMap.Ysize) + { + height = y + cHeight; + } + else + { + height = VMap.Ysize; + } + y = 0; + } + else + { + y2 = 0; + if (y + cHeight < VMap.Ysize) + { + height = cHeight; + } + else + { + height = VMap.Ysize - y; + } + } + + sub_8058B54( + /*x*/ 0, y, + connectedMapHeader, + x2, y2, + /*width*/ 7, height); + } +} + +void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +{ + s32 x, y; + s32 y2; + s32 height; + s32 cHeight; + if (connectedMapHeader) + { + cHeight = connectedMapHeader->mapData->height; + x = mapHeader->mapData->width + 7; + y = offset + 7; + if (y < 0) + { + y2 = -y; + if (y + cHeight < VMap.Ysize) + { + height = y + cHeight; + } + else + { + height = VMap.Ysize; + } + y = 0; + } + else + { + y2 = 0; + if (y + cHeight < VMap.Ysize) + { + height = cHeight; + } + else + { + height = VMap.Ysize - y; + } + } + + sub_8058B54( + x, y, + connectedMapHeader, + /*x2*/ 0, y2, + /*width*/ 8, height); + } +} + +union Block +{ + struct + { + u16 block:10; + u16 collision:2; + u16 elevation:4; + } block; + u16 value; +}; + +#define MapGridGetBorderTileAt(x, y) ({ \ + u16 block; \ + s32 xprime; \ + s32 yprime; \ + \ + struct MapData *mapData = gMapHeader.mapData; \ + \ + xprime = x - 7; \ + xprime += 8 * mapData->unk18; \ + xprime %= mapData->unk18; \ + \ + yprime = y - 7; \ + yprime += 8 * mapData->unk19; \ + yprime %= mapData->unk19; \ + \ + block = mapData->border[xprime + yprime * mapData->unk18]; \ + block |= 0xC00; \ + block; \ +}) + +#define MapGridGetBorderTileAt2(x, y) ({ \ + u16 block; \ + s32 xprime; \ + s32 yprime; \ + \ + struct MapData *mapData = gMapHeader.mapData; \ + \ + xprime = x - 7; \ + xprime += 8 * mapData->unk18; \ + xprime %= mapData->unk18; \ + \ + yprime = y - 7; \ + yprime += 8 * mapData->unk19; \ + yprime %= mapData->unk19; \ + \ + block = mapData->border[xprime + yprime * mapData->unk18] | 0xC00; \ + block; \ +}) + +#define AreCoordsWithinMapGridBounds(x, y) (x >= 0 && x < VMap.Xsize && y >= 0 && y < VMap.Ysize) + +#define MapGridGetTileAt(x, y) (AreCoordsWithinMapGridBounds(x, y) ? VMap.map[x + VMap.Xsize * y] : MapGridGetBorderTileAt2(x, y)) + +u8 MapGridGetZCoordAt(s32 x, s32 y) +{ + u16 block = MapGridGetTileAt(x, y); + + if (block == 0x3ff) + { + return 0; + } + + return block >> 12; +} + +u8 MapGridIsImpassableAt(s32 x, s32 y) +{ + + u16 block = MapGridGetTileAt(x, y); + + if (block == 0x3ff) + { + return 1; + } + + return (block & 0xc00) >> 10; +} + +u32 MapGridGetMetatileIdAt(s32 x, s32 y) +{ + u16 block = MapGridGetTileAt(x, y); + + if (block == 0x3FF) + { + return MapGridGetBorderTileAt(x, y) & 0x3FF; + } + return block & 0x3FF; +} + +u32 sub_8058F1C(u32 original, u8 bit) +{ + if (bit >= 8) + return original; + + return (original & gUnknown_8352EF0[bit]) >> gUnknown_8352F10[bit]; +} + +u32 sub_8058F48(s16 x, s16 y, u8 z) +{ + u16 metatileId = MapGridGetMetatileIdAt(x, y); + return GetBehaviorByMetatileIdAndMapData(gMapHeader.mapData, metatileId, z); +} + +u32 MapGridGetMetatileBehaviorAt(s32 x, s32 y) +{ + return sub_8058F48(x, y, 0); +} + +u8 MapGridGetMetatileLayerTypeAt(s32 x, s32 y) +{ + return sub_8058F48(x, y, 6); +} + +void MapGridSetMetatileIdAt(s32 x, s32 y, u16 metatile) +{ + s32 i; + if (x >= 0 && x < VMap.Xsize + && y >= 0 && y < VMap.Ysize) + { + i = x + y * VMap.Xsize; + VMap.map[i] = (VMap.map[i] & 0xf000) | (metatile & 0xfff); + } +} + +void MapGridSetMetatileEntryAt(s32 x, s32 y, u16 metatile) +{ + s32 i; + if (x >= 0 && x < VMap.Xsize + && y >= 0 && y < VMap.Ysize) + { + i = x + VMap.Xsize * y; + VMap.map[i] = metatile; + } +} + +void sub_8059024(s32 x, s32 y, bool32 arg2) +{ + if (x >= 0 && x < VMap.Xsize + && y >= 0 && y < VMap.Ysize) + { + if (arg2) + { + VMap.map[x + VMap.Xsize * y] |= 0x0C00; + } + else + { + VMap.map[x + VMap.Xsize * y] &= ~0x0C00; + } + } +} + +u32 GetBehaviorByMetatileIdAndMapData(struct MapData *mapData, u16 metatile, u8 attr) +{ + u32 * attributes; + + if (metatile < NUM_METATILES_IN_PRIMARY) + { + attributes = mapData->primaryTileset->metatileAttributes; + return sub_8058F1C(attributes[metatile], attr); + } + else if (metatile < 0x400) + { + attributes = mapData->secondaryTileset->metatileAttributes; + return sub_8058F1C(attributes[metatile - NUM_METATILES_IN_PRIMARY], attr); + } + else + { + return 0xFF; + } +} + +void save_serialize_map(void) +{ + s32 i, j; + s32 x, y; + u16 *mapView; + s32 width; + mapView = gSaveBlock2Ptr->mapView; + width = VMap.Xsize; + x = gSaveBlock1Ptr->pos.x; + y = gSaveBlock1Ptr->pos.y; + for (i = y; i < y + 14; i++) + { + for (j = x; j < x + 15; j++) + { + *mapView++ = gBackupMapData[width * i + j]; + } + } +} + +bool32 SavedMapViewIsEmpty(void) +{ + u16 i; + u32 marker = 0; + + // BUG: This loop extends past the bounds of the mapView array. Its size is only 0x100. + for (i = 0; i < 0x200; i++) + marker |= gSaveBlock2Ptr->mapView[i]; + + if (marker == 0) + return TRUE; + else + return FALSE; +} + +void ClearSavedMapView(void) +{ + CpuFill16(0, gSaveBlock2Ptr->mapView, sizeof(gSaveBlock2Ptr->mapView)); +} + +void LoadSavedMapView(void) +{ + s32 i, j; + s32 x, y; + u16 *mapView; + s32 width; + mapView = gSaveBlock2Ptr->mapView; + if (!SavedMapViewIsEmpty()) + { + width = VMap.Xsize; + x = gSaveBlock1Ptr->pos.x; + y = gSaveBlock1Ptr->pos.y; + for (i = y; i < y + 14; i++) + { + for (j = x; j < x + 15; j++) + { + gBackupMapData[j + width * i] = *mapView; + mapView++; + } + } + ClearSavedMapView(); + } +} + +void sub_8059250(u8 a1) +{ + s32 width; + u16 *mapView; + s32 x0, y0; + s32 x2, y2; + u16 *src, *dest; + s32 srci, desti; + s32 r9, r8; + s32 x, y; + s32 i, j; + mapView = gSaveBlock2Ptr->mapView; + width = VMap.Xsize; + r9 = 0; + r8 = 0; + x0 = gSaveBlock1Ptr->pos.x; + y0 = gSaveBlock1Ptr->pos.y; + x2 = 15; + y2 = 14; + switch (a1) + { + case CONNECTION_NORTH: + y0 += 1; + y2 = 13; + break; + case CONNECTION_SOUTH: + r8 = 1; + y2 = 13; + break; + case CONNECTION_WEST: + x0 += 1; + x2 = 14; + break; + case CONNECTION_EAST: + r9 = 1; + x2 = 14; + break; + } + for (y = 0; y < y2; y++) + { + i = 0; + j = 0; + for (x = 0; x < x2; x++) + { + desti = width * (y + y0); + srci = (y + r8) * 15 + r9; + src = &mapView[srci + i]; + dest = &gBackupMapData[x0 + desti + j]; + *dest = *src; + i++; + j++; + } + } + ClearSavedMapView(); +} + +s32 GetMapBorderIdAt(s32 x, s32 y) +{ + if (MapGridGetTileAt(x, y) == 0x3FF) + { + return -1; + } + + if (x >= VMap.Xsize - 8) + { + if (!gMapConnectionFlags.east) + { + return -1; + } + return CONNECTION_EAST; + } + + if (x < 7) + { + if (!gMapConnectionFlags.west) + { + return -1; + } + return CONNECTION_WEST; + } + + if (y >= VMap.Ysize - 7) + { + if (!gMapConnectionFlags.south) + { + return -1; + } + return CONNECTION_SOUTH; + } + + if (y < 7) + { + if (!gMapConnectionFlags.north) + { + return -1; + } + return CONNECTION_NORTH; + } + + return 0; +} + +s32 GetPostCameraMoveMapBorderId(s32 x, s32 y) +{ + return GetMapBorderIdAt(7 + gSaveBlock1Ptr->pos.x + x, 7 + gSaveBlock1Ptr->pos.y + y); +} + +bool32 CanCameraMoveInDirection(s32 direction) +{ + s32 x, y; + + x = gSaveBlock1Ptr->pos.x + 7 + gDirectionToVectors[direction].x; + y = gSaveBlock1Ptr->pos.y + 7 + gDirectionToVectors[direction].y; + if (GetMapBorderIdAt(x, y) == -1) + { + return FALSE; + } + return TRUE; +} + +void sub_80594AC(struct MapConnection *connection, int direction, s32 x, s32 y) +{ + struct MapHeader const *mapHeader; + mapHeader = mapconnection_get_mapheader(connection); + switch (direction) + { + case CONNECTION_EAST: + gSaveBlock1Ptr->pos.x = -x; + gSaveBlock1Ptr->pos.y -= connection->offset; + break; + case CONNECTION_WEST: + gSaveBlock1Ptr->pos.x = mapHeader->mapData->width; + gSaveBlock1Ptr->pos.y -= connection->offset; + break; + case CONNECTION_SOUTH: + gSaveBlock1Ptr->pos.x -= connection->offset; + gSaveBlock1Ptr->pos.y = -y; + break; + case CONNECTION_NORTH: + gSaveBlock1Ptr->pos.x -= connection->offset; + gSaveBlock1Ptr->pos.y = mapHeader->mapData->height; + break; + } +} + +bool8 CameraMove(s32 x, s32 y) +{ + u32 direction; + struct MapConnection *connection; + s32 old_x, old_y; + gCamera.active = FALSE; + direction = GetPostCameraMoveMapBorderId(x, y); + if (direction + 1 <= 1) + { + gSaveBlock1Ptr->pos.x += x; + gSaveBlock1Ptr->pos.y += y; + } + else + { + save_serialize_map(); + old_x = gSaveBlock1Ptr->pos.x; + old_y = gSaveBlock1Ptr->pos.y; + connection = sub_8059600(direction, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); + sub_80594AC(connection, direction, x, y); + sub_8055864(connection->mapGroup, connection->mapNum); + gCamera.active = TRUE; + gCamera.x = old_x - gSaveBlock1Ptr->pos.x; + gCamera.y = old_y - gSaveBlock1Ptr->pos.y; + gSaveBlock1Ptr->pos.x += x; + gSaveBlock1Ptr->pos.y += y; + sub_8059250(direction); + } + return gCamera.active; +} + +struct MapConnection *sub_8059600(u8 direction, s32 x, s32 y) +{ + s32 count; + struct MapConnection *connection; + s32 i; + count = gMapHeader.connections->count; + connection = gMapHeader.connections->connections; + for (i = 0; i < count; i++, connection++) + { + if (connection->direction == direction && sub_8059658(direction, x, y, connection) == TRUE) + return connection; + } + return NULL; + +} + +bool8 sub_8059658(u8 direction, s32 x, s32 y, struct MapConnection *connection) +{ + struct MapHeader const *mapHeader; + mapHeader = mapconnection_get_mapheader(connection); + switch (direction) + { + case CONNECTION_SOUTH: + case CONNECTION_NORTH: + return sub_80596BC(x, gMapHeader.mapData->width, mapHeader->mapData->width, connection->offset); + case CONNECTION_WEST: + case CONNECTION_EAST: + return sub_80596BC(y, gMapHeader.mapData->height, mapHeader->mapData->height, connection->offset); + } + return FALSE; +} + +bool8 sub_80596BC(s32 x, s32 src_width, s32 dest_width, s32 offset) +{ + s32 offset2 = max(offset, 0); + + if (dest_width + offset < src_width) + src_width = dest_width + offset; + + if (offset2 <= x && x <= src_width) + return TRUE; + + return FALSE; +} + +bool32 sub_80596E8(s32 x, s32 width) +{ + if (x >= 0 && x < width) + return TRUE; + + return FALSE; +} + +s32 sub_80596FC(struct MapConnection *connection, s32 x, s32 y) +{ + struct MapHeader const *mapHeader; + mapHeader = mapconnection_get_mapheader(connection); + switch (connection->direction) + { + case CONNECTION_SOUTH: + case CONNECTION_NORTH: + return sub_80596E8(x - connection->offset, mapHeader->mapData->width); + case CONNECTION_WEST: + case CONNECTION_EAST: + return sub_80596E8(y - connection->offset, mapHeader->mapData->height); + } + return FALSE; +} + +struct MapConnection *sub_805973C(s16 x, s16 y) +{ + s32 count; + struct MapConnection *connection; + s32 i; + u8 direction; + if (!gMapHeader.connections) + { + return NULL; + } + else + { + count = gMapHeader.connections->count; + connection = gMapHeader.connections->connections; + for (i = 0; i < count; i++, connection++) + { + direction = connection->direction; + if ((direction == CONNECTION_DIVE || direction == CONNECTION_EMERGE) + || (direction == CONNECTION_NORTH && y > 6) + || (direction == CONNECTION_SOUTH && y < gMapHeader.mapData->height + 7) + || (direction == CONNECTION_WEST && x > 6) + || (direction == CONNECTION_EAST && x < gMapHeader.mapData->width + 7)) + { + continue; + } + if (sub_80596FC(connection, x - 7, y - 7) == TRUE) + { + return connection; + } + } + } + return NULL; +} + +void SetCameraFocusCoords(u16 x, u16 y) +{ + gSaveBlock1Ptr->pos.x = x - 7; + gSaveBlock1Ptr->pos.y = y - 7; +} + +void GetCameraFocusCoords(u16 *x, u16 *y) +{ + *x = gSaveBlock1Ptr->pos.x + 7; + *y = gSaveBlock1Ptr->pos.y + 7; +} + +void SetCameraCoords(u16 x, u16 y) +{ + gSaveBlock1Ptr->pos.x = x; + gSaveBlock1Ptr->pos.y = y; +} + +void GetCameraCoords(u16 *x, u16 *y) +{ + *x = gSaveBlock1Ptr->pos.x; + *y = gSaveBlock1Ptr->pos.y; +} +void copy_tileset_patterns_to_vram(struct Tileset const *tileset, u16 numTiles, u16 offset) +{ + if (tileset) + { + if (!tileset->isCompressed) + LoadBgTiles(2, tileset->tiles, numTiles * 32, offset); + else + sub_80F68F0(2, tileset->tiles, numTiles * 32, offset, 0); + } +} + +void copy_tileset_patterns_to_vram2(struct Tileset const *tileset, u16 numTiles, u16 offset) +{ + if (tileset) + { + if (!tileset->isCompressed) + LoadBgTiles(2, tileset->tiles, numTiles * 32, offset); + else + sub_80F69E8(2, tileset->tiles, numTiles * 32, offset, 0); + } +} + +void sub_80598CC(u16 a0, u16 a1) +{ + switch (gUnknown_2036E28) + { + case 0: + return; + case 1: + TintPalette_GrayScale(gPlttBufferUnfaded + a0, a1); + break; + case 2: + TintPalette_SepiaTone(gPlttBufferUnfaded + a0, a1); + break; + case 3: + sub_8111F38(a0, a1); + TintPalette_GrayScale(gPlttBufferUnfaded + a0, a1); + break; + default: + return; + } + CpuCopy16(gPlttBufferUnfaded + a0, gPlttBufferFaded + a0, a1 * sizeof(u16)); +} + +void sub_8059948(u8 a0, u8 a1) +{ + switch (gUnknown_2036E28) + { + case 0: + return; + case 1: + TintPalette_GrayScale(gPlttBufferUnfaded + a0 * 16, a1 * 16); + break; + case 2: + TintPalette_SepiaTone(gPlttBufferUnfaded + a0 * 16, a1 * 16); + break; + case 3: + sub_8111F38(a0 * 16, a1 * 16); + TintPalette_GrayScale(gPlttBufferUnfaded + a0 * 16, a1 * 16); + break; + default: + return; + } + CpuFastCopy(gPlttBufferUnfaded + a0 * 16, gPlttBufferFaded + a0 * 16, a1 * 16 * sizeof(u16)); +} + +void apply_map_tileset_palette(struct Tileset const *tileset, u16 destOffset, u16 size) +{ + u16 black = RGB_BLACK; + + if (tileset) + { + if (tileset->isSecondary == FALSE) + { + LoadPalette(&black, destOffset, 2); + LoadPalette(((u16*)tileset->palettes) + 1, destOffset + 1, size - 2); + sub_80598CC(destOffset + 1, (size - 2) >> 1); + } + else if (tileset->isSecondary == TRUE) + { + LoadPalette(((u16*)tileset->palettes) + (NUM_PALS_IN_PRIMARY * 16), destOffset, size); + sub_80598CC(destOffset, size >> 1); + } + else + { + LoadCompressedPalette((u32*)tileset->palettes, destOffset, size); + sub_80598CC(destOffset, size >> 1); + } + } +} + +void copy_map_tileset1_to_vram(const struct MapData *mapData) +{ + copy_tileset_patterns_to_vram(mapData->primaryTileset, NUM_TILES_IN_PRIMARY, 0); +} + +void copy_map_tileset2_to_vram(const struct MapData *mapData) +{ + copy_tileset_patterns_to_vram(mapData->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); +} + +void copy_map_tileset2_to_vram_2(const struct MapData *mapData) +{ + copy_tileset_patterns_to_vram2(mapData->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); +} + +void apply_map_tileset1_palette(const struct MapData *mapData) +{ + apply_map_tileset_palette(mapData->primaryTileset, 0, NUM_PALS_IN_PRIMARY * 16 * 2); +} + +void apply_map_tileset2_palette(const struct MapData *mapData) +{ + apply_map_tileset_palette(mapData->secondaryTileset, NUM_PALS_IN_PRIMARY * 16, (NUM_PALS_TOTAL - NUM_PALS_IN_PRIMARY) * 16 * 2); +} + +void copy_map_tileset1_tileset2_to_vram(struct MapData const *mapData) +{ + if (mapData) + { + copy_tileset_patterns_to_vram2(mapData->primaryTileset, NUM_TILES_IN_PRIMARY, 0); + copy_tileset_patterns_to_vram2(mapData->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); + } +} + +void apply_map_tileset1_tileset2_palette(struct MapData const *mapData) +{ + if (mapData) + { + apply_map_tileset1_palette(mapData); + apply_map_tileset2_palette(mapData); + } +}
\ No newline at end of file diff --git a/src/quest_log.c b/src/quest_log.c index 4f462505a..a01cbde2d 100644 --- a/src/quest_log.c +++ b/src/quest_log.c @@ -4312,7 +4312,7 @@ u16 * sub_8114C68(u16 * a0, const u16 * a1) const u16 * sub_8114C8C(const u16 * a0) { const u16 *r4 = sub_8113E88(28, a0); - sub_8099E90(r4[0], gStringVar1); + CopyItemName(r4[0], gStringVar1); StringExpandPlaceholders(gStringVar4, gUnknown_841A391); return r4 + 1; } @@ -4329,7 +4329,7 @@ u16 * sub_8114CC0(u16 * a0, const u16 * a1) const u16 * sub_8114CE4(const u16 * a0) { const u16 *r4 = sub_8113E88(29, a0); - sub_8099E90(r4[0], gStringVar1); + CopyItemName(r4[0], gStringVar1); StringExpandPlaceholders(gStringVar4, gUnknown_841A3DA); return r4 + 1; } diff --git a/src/save.c b/src/save.c index ef38d8b17..761e3c92d 100644 --- a/src/save.c +++ b/src/save.c @@ -69,7 +69,7 @@ const struct SaveSectionOffsets gSaveSectionOffsets[] = extern void DoSaveFailedScreen(u8 saveType); // save_failed_screen extern void sub_800AB9C(void); // link extern bool8 sub_800A4BC(void); // link -extern void sub_80590D8(void); // fieldmap +extern void save_serialize_map(void); // fieldmap extern void sub_804C1C0(void); // load_save extern void sav2_gender2_inplace_and_xFE(void); // load_save @@ -867,7 +867,7 @@ void sub_80DA634(u8 taskId) case 2: if (sub_800A4BC()) { - sub_80590D8(); + save_serialize_map(); gTasks[taskId].data[0] = 3; } break; diff --git a/src/scrcmd.c b/src/scrcmd.c new file mode 100644 index 000000000..12b35daa4 --- /dev/null +++ b/src/scrcmd.c @@ -0,0 +1,2267 @@ +#include "global.h" +#include "gba/isagbprint.h" +#include "palette.h" +#include "script.h" +#include "mystery_event_script.h" +#include "event_data.h" +#include "random.h" +#include "item.h" +#include "overworld.h" +#include "field_screen_effect.h" +#include "quest_log.h" +#include "map_preview_screen.h" +#include "field_weather.h" +#include "field_tasks.h" +#include "field_fadetransition.h" +#include "field_player_avatar.h" +#include "sound.h" +#include "script_movement.h" +#include "field_map_obj.h" +#include "field_map_obj_helpers.h" +#include "map_obj_lock.h" +#include "field_message_box.h" +#include "new_menu_helpers.h" +#include "window.h" +#include "start_menu.h" +#include "script_menu.h" +#include "string_util.h" +#include "data2.h" +#include "field_specials.h" +#include "constants/items.h" +#include "script_pokemon_util_80A0058.h" +#include "pokemon_storage_system.h" +#include "party_menu.h" +#include "money.h" +#include "coins.h" +#include "battle_setup.h" +#include "shop.h" +#include "script_pokemon_80F8.h" +#include "slot_machine.h" +#include "field_effect.h" +#include "fieldmap.h" +#include "field_door.h" +#include "scrcmd.h" + +extern u16 (*const gSpecials[])(void); +extern u16 (*const gSpecialsEnd[])(void); +extern const u8 *const gStdScripts[]; +extern const u8 *const gStdScriptsEnd[]; + +static bool8 sub_806B93C(struct ScriptContext * ctx); +static u8 sub_806B96C(struct ScriptContext * ctx); + +EWRAM_DATA ptrdiff_t gVScriptOffset = 0; +EWRAM_DATA u8 gUnknown_20370AC = 0; +EWRAM_DATA u16 sPauseCounter = 0; +EWRAM_DATA u16 sMovingNpcId = 0; +EWRAM_DATA u16 sMovingNpcMapBank = 0; +EWRAM_DATA u16 sMovingNpcMapId = 0; +EWRAM_DATA u16 sFieldEffectScriptId = 0; + +IWRAM_DATA struct ScriptContext * gUnknown_3005070; + +extern u8 gSelectedEventObject; + +// This is defined in here so the optimizer can't see its value when compiling +// script.c. +void * const gNullScriptPtr = NULL; + +static const u8 sScriptConditionTable[6][3] = +{ +// < = > + 1, 0, 0, // < + 0, 1, 0, // = + 0, 0, 1, // > + 1, 1, 0, // <= + 0, 1, 1, // >= + 1, 0, 1, // != +}; + +bool8 ScrCmd_nop(struct ScriptContext *ctx) +{ + return FALSE; +} + +bool8 ScrCmd_nop1(struct ScriptContext *ctx) +{ + return FALSE; +} + +bool8 ScrCmd_end(struct ScriptContext *ctx) +{ + StopScript(ctx); + return FALSE; +} + +bool8 ScrCmd_gotonative(struct ScriptContext *ctx) +{ + bool8 (*func)(void) = (bool8 (*)(void))ScriptReadWord(ctx); + SetupNativeScript(ctx, func); + return TRUE; +} + +bool8 ScrCmd_special(struct ScriptContext *ctx) +{ + u16 (*const *specialPtr)(void) = gSpecials + ScriptReadHalfword(ctx); + if (specialPtr < gSpecialsEnd) + (*specialPtr)(); + else + AGB_ASSERT_EX(0, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/scrcmd.c", 241); + return FALSE; +} + +bool8 ScrCmd_specialvar(struct ScriptContext *ctx) +{ + u16 * varPtr = GetVarPointer(ScriptReadHalfword(ctx)); + u16 (*const *specialPtr)(void) = gSpecials + ScriptReadHalfword(ctx); + if (specialPtr < gSpecialsEnd) + *varPtr = (*specialPtr)(); + else + AGB_ASSERT_EX(0, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/scrcmd.c", 263); + return FALSE; +} + +bool8 ScrCmd_callnative(struct ScriptContext *ctx) +{ + void (*func )(void) = ((void (*)(void))ScriptReadWord(ctx)); + func(); + return FALSE; +} + +bool8 ScrCmd_waitstate(struct ScriptContext *ctx) +{ + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_goto(struct ScriptContext *ctx) +{ + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + ScriptJump(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_return(struct ScriptContext *ctx) +{ + ScriptReturn(ctx); + return FALSE; +} + +bool8 ScrCmd_call(struct ScriptContext *ctx) +{ + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + ScriptCall(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_goto_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptJump(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_call_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptCall(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_setvaddress(struct ScriptContext *ctx) +{ + u32 addr1 = (u32)ctx->scriptPtr - 1; + u32 addr2 = ScriptReadWord(ctx); + + gVScriptOffset = addr2 - addr1; + return FALSE; +} + +bool8 ScrCmd_vgoto(struct ScriptContext *ctx) +{ + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + ScriptJump(ctx, scrptr - gVScriptOffset); + return FALSE; +} + +bool8 ScrCmd_vcall(struct ScriptContext *ctx) +{ + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx); + ScriptCall(ctx, scrptr - gVScriptOffset); + return FALSE; +} + +bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx) - gVScriptOffset; + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptJump(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 * scrptr = (const u8 *)ScriptReadWord(ctx) - gVScriptOffset; + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptCall(ctx, scrptr); + return FALSE; +} + +bool8 ScrCmd_gotostd(struct ScriptContext *ctx) +{ + u8 stdIdx = ScriptReadByte(ctx); + const u8 *const * script = gStdScripts + stdIdx; + if (script < gStdScriptsEnd) + ScriptJump(ctx, *script); + return FALSE; +} + +bool8 ScrCmd_callstd(struct ScriptContext *ctx) +{ + u8 stdIdx = ScriptReadByte(ctx); + const u8 *const * script = gStdScripts + stdIdx; + if (script < gStdScriptsEnd) + ScriptCall(ctx, *script); + return FALSE; +} + +bool8 ScrCmd_gotostd_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + u8 stdIdx = ScriptReadByte(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + { + const u8 *const * script = gStdScripts + stdIdx; + if (script < gStdScriptsEnd) + ScriptJump(ctx, *script); + } + return FALSE; +} + +bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + u8 stdIdx = ScriptReadByte(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + { + const u8 *const * script = gStdScripts + stdIdx; + if (script < gStdScriptsEnd) + ScriptCall(ctx, *script); + } + return FALSE; +} + +bool8 ScrCmd_gotoram(struct ScriptContext *ctx) +{ + ScriptJump(ctx, gRAMScriptPtr); + return FALSE; +} + +bool8 ScrCmd_killscript(struct ScriptContext *ctx) +{ + ClearRamScript(); + StopScript(ctx); + return TRUE; +} + +bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx) +{ + SetMysteryEventScriptStatus(ScriptReadByte(ctx)); + return FALSE; +} + +bool8 ScrCmd_cmdCF(struct ScriptContext *ctx) +{ + const u8 * script = sub_8069E48(); + if (script != NULL) + { + gRAMScriptPtr = ctx->scriptPtr; + ScriptJump(ctx, script); + } + return FALSE; +} + +bool8 ScrCmd_loadword(struct ScriptContext *ctx) +{ + u8 which = ScriptReadByte(ctx); + ctx->data[which] = ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) +{ + u8 which = ScriptReadByte(ctx); + ctx->data[which] = *(const u8 *)ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_writebytetoaddr(struct ScriptContext *ctx) +{ + u8 value = ScriptReadByte(ctx); + *(u8 *)ScriptReadWord(ctx) = value; + return FALSE; +} + +bool8 ScrCmd_loadbyte(struct ScriptContext *ctx) +{ + u8 which = ScriptReadByte(ctx); + ctx->data[which] = ScriptReadByte(ctx); + return FALSE; +} + +bool8 ScrCmd_setptrbyte(struct ScriptContext *ctx) +{ + u8 which = ScriptReadByte(ctx); + *(u8 *)ScriptReadWord(ctx) = ctx->data[which]; + return FALSE; +} + +bool8 ScrCmd_copylocal(struct ScriptContext *ctx) +{ + u8 whichDst = ScriptReadByte(ctx); + u8 whichSrc = ScriptReadByte(ctx); + ctx->data[whichDst] = ctx->data[whichSrc]; + return FALSE; +} + +bool8 ScrCmd_copybyte(struct ScriptContext *ctx) +{ + u8 * dest = (u8 *)ScriptReadWord(ctx); + *dest = *(const u8 *)ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_setvar(struct ScriptContext *ctx) +{ + u16 * varPtr = GetVarPointer(ScriptReadHalfword(ctx)); + *varPtr = ScriptReadHalfword(ctx); + return FALSE; +} + +bool8 ScrCmd_copyvar(struct ScriptContext *ctx) +{ + u16 * destPtr = GetVarPointer(ScriptReadHalfword(ctx)); + u16 * srcPtr = GetVarPointer(ScriptReadHalfword(ctx)); + *destPtr = *srcPtr; + return FALSE; +} + +bool8 ScrCmd_setorcopyvar(struct ScriptContext *ctx) +{ + u16 * destPtr = GetVarPointer(ScriptReadHalfword(ctx)); + *destPtr = VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +u8 compare_012(u16 left, u16 right) +{ + if (left < right) + return 0; + else if (left == right) + return 1; + else + return 2; +} + +// comparelocaltolocal +bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +// comparelocaltoimm +bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ScriptReadByte(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ScriptReadByte(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) +{ + const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); + const u16 value2 = ScriptReadHalfword(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx) +{ + const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); + const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); + + ctx->comparisonResult = compare_012(*ptr1, *ptr2); + return FALSE; +} + +bool8 ScrCmd_addvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr += ScriptReadHalfword(ctx); + return FALSE; +} + +bool8 ScrCmd_subvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr -= VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_random(struct ScriptContext *ctx) +{ + u16 max = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = Random() % max; + return FALSE; +} + +bool8 ScrCmd_giveitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = AddBagItem(itemId, (u8)quantity); + sub_809A824(itemId); + return FALSE; +} + +bool8 ScrCmd_takeitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = RemoveBagItem(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitemspace(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = CheckBagHasSpace(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = CheckBagHasItem(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitemtype(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = GetPocketByItemId(itemId); + return FALSE; +} + +bool8 ScrCmd_givepcitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = AddPCItem(itemId, quantity); + return FALSE; +} + +bool8 ScrCmd_checkpcitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = CheckPCHasItem(itemId, quantity); + return FALSE; +} + +bool8 ScrCmd_givedecoration(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + +// gSpecialVar_Result = DecorationAdd(decorId); + return FALSE; +} + +bool8 ScrCmd_takedecoration(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + +// gSpecialVar_Result = DecorationRemove(decorId); + return FALSE; +} + +bool8 ScrCmd_checkdecorspace(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + +// gSpecialVar_Result = DecorationCheckSpace(decorId); + return FALSE; +} + +bool8 ScrCmd_checkdecor(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + +// gSpecialVar_Result = CheckHasDecoration(decorId); + return FALSE; +} + +bool8 ScrCmd_setflag(struct ScriptContext *ctx) +{ + FlagSet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_clearflag(struct ScriptContext *ctx) +{ + FlagClear(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_checkflag(struct ScriptContext *ctx) +{ + ctx->comparisonResult = FlagGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_incrementgamestat(struct ScriptContext *ctx) +{ + IncrementGameStat(ScriptReadByte(ctx)); + return FALSE; +} + +bool8 ScrCmd_comparestattoword(struct ScriptContext *ctx) +{ + u8 statIdx = ScriptReadByte(ctx); + u32 value = ScriptReadWord(ctx); + u32 statValue = GetGameStat(statIdx); + + if (statValue < value) + ctx ->comparisonResult = 0; + else if (statValue == value) + ctx->comparisonResult = 1; + else + ctx->comparisonResult = 2; + return FALSE; +} + +bool8 ScrCmd_cmdD0(struct ScriptContext *ctx) +{ + u16 value = ScriptReadHalfword(ctx); + sub_8115748(value); + sub_80F85BC(value); + return FALSE; +} + +bool8 ScrCmd_animateflash(struct ScriptContext *ctx) +{ + sub_807F028(ScriptReadByte(ctx)); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_setflashradius(struct ScriptContext *ctx) +{ + u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetFlashLevel(flashLevel); + return FALSE; +} + +static bool8 IsPaletteNotActive(void) +{ + if (!gPaletteFade.active) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) +{ + fade_screen(ScriptReadByte(ctx), 0); + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + +bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx) +{ + u8 mode = ScriptReadByte(ctx); + u8 speed = ScriptReadByte(ctx); + + fade_screen(mode, speed); + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + +static bool8 RunPauseTimer(void) +{ + sPauseCounter--; + + if (sPauseCounter == 0) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_delay(struct ScriptContext *ctx) +{ + sPauseCounter = ScriptReadHalfword(ctx); + SetupNativeScript(ctx, RunPauseTimer); + return TRUE; +} + +bool8 ScrCmd_initclock(struct ScriptContext *ctx) +{ +// u8 hour = VarGet(ScriptReadHalfword(ctx)); +// u8 minute = VarGet(ScriptReadHalfword(ctx)); +// +// RtcInitLocalTimeOffset(hour, minute); + return FALSE; +} + +bool8 ScrCmd_dodailyevents(struct ScriptContext *ctx) +{ +// DoTimeBasedEvents(); + return FALSE; +} + +bool8 ScrCmd_gettime(struct ScriptContext *ctx) +{ +// RtcCalcLocalTime(); +// gSpecialVar_0x8000 = gLocalTime.hours; +// gSpecialVar_0x8001 = gLocalTime.minutes; +// gSpecialVar_0x8002 = gLocalTime.seconds; + gSpecialVar_0x8000 = 0; + gSpecialVar_0x8001 = 0; + gSpecialVar_0x8002 = 0; + return FALSE; +} + +bool8 ScrCmd_setweather(struct ScriptContext *ctx) +{ + u16 weather = VarGet(ScriptReadHalfword(ctx)); + + SetSav1Weather(weather); + return FALSE; +} + +bool8 ScrCmd_resetweather(struct ScriptContext *ctx) +{ + SetSav1WeatherFromCurrMapHeader(); + return FALSE; +} + +bool8 ScrCmd_doweather(struct ScriptContext *ctx) +{ + DoCurrentWeather(); + return FALSE; +} + +bool8 ScrCmd_setstepcallback(struct ScriptContext *ctx) +{ + ActivatePerStepCallback(ScriptReadByte(ctx)); + return FALSE; +} + +bool8 ScrCmd_setmaplayoutindex(struct ScriptContext *ctx) +{ + u16 value = VarGet(ScriptReadHalfword(ctx)); + + SetCurrentMapLayout(value); + return FALSE; +} + +bool8 ScrCmd_warp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoWarp(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_warpsilent(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoDiveWarp(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_warpdoor(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoDoorWarp(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_warphole(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u16 x; + u16 y; + + PlayerGetDestCoords(&x, &y); + if (mapGroup == 0xFF && mapNum == 0xFF) + SetWarpDestinationToFixedHoleWarp(x - 7, y - 7); + else + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); + DoFallWarp(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_warpteleport(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_807E59C(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_warpD1(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_805DAE4(player_get_direction_lower_nybble()); + sub_807E500(); + ResetInitialPlayerAvatarState(); + return TRUE; +} + +bool8 ScrCmd_setwarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setdynamicwarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + SetDynamicWarpWithCoords(0, mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setdivewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + SetFixedDiveWarp(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setholewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + SetFixedHoleWarp(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setescapewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + SetEscapeWarp(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_getplayerxy(struct ScriptContext *ctx) +{ + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + + *pX = gSaveBlock1Ptr->pos.x; + *pY = gSaveBlock1Ptr->pos.y; + return FALSE; +} + +bool8 ScrCmd_getpartysize(struct ScriptContext *ctx) +{ + gSpecialVar_Result = CalculatePlayerPartyCount(); + return FALSE; +} + +bool8 ScrCmd_playse(struct ScriptContext *ctx) +{ + PlaySE(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForSoundEffectFinish(void) +{ + if (!IsSEPlaying()) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitse(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, WaitForSoundEffectFinish); + return TRUE; +} + +bool8 ScrCmd_playfanfare(struct ScriptContext *ctx) +{ + PlayFanfare(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForFanfareFinish(void) +{ + return IsFanfareTaskInactive(); +} + +bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, WaitForFanfareFinish); + return TRUE; +} + +bool8 ScrCmd_playbgm(struct ScriptContext *ctx) +{ + u16 songId = ScriptReadHalfword(ctx); + bool8 val = ScriptReadByte(ctx); + + if (gUnknown_203ADFA == 2 || gUnknown_203ADFA == 3) + return FALSE; + if (val == TRUE) + Overworld_SetSavedMusic(songId); + PlayNewMapMusic(songId); + return FALSE; +} + +bool8 ScrCmd_savebgm(struct ScriptContext *ctx) +{ + Overworld_SetSavedMusic(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_fadedefaultbgm(struct ScriptContext *ctx) +{ + if (gUnknown_203ADFA == 2 || gUnknown_203ADFA == 3) + return FALSE; + Overworld_ChangeMusicToDefault(); + return FALSE; +} + +bool8 ScrCmd_fadenewbgm(struct ScriptContext *ctx) +{ + u16 music = ScriptReadHalfword(ctx); + if (gUnknown_203ADFA == 2 || gUnknown_203ADFA == 3) + return FALSE; + Overworld_ChangeMusicTo(music); + return FALSE; +} + +bool8 ScrCmd_fadeoutbgm(struct ScriptContext *ctx) +{ + u8 speed = ScriptReadByte(ctx); + + if (gUnknown_203ADFA == 2 || gUnknown_203ADFA == 3) + return FALSE; + if (speed != 0) + FadeOutBGMTemporarily(4 * speed); + else + FadeOutBGMTemporarily(4); + SetupNativeScript(ctx, IsBGMPausedOrStopped); + return TRUE; +} + +bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx) +{ + u8 speed = ScriptReadByte(ctx); + + if (gUnknown_203ADFA == 2 || gUnknown_203ADFA == 3) + return FALSE; + if (speed != 0) + FadeInBGM(4 * speed); + else + FadeInBGM(4); + return FALSE; +} + +bool8 ScrCmd_applymovement(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + const void *movementScript = (const void *)ScriptReadWord(ctx); + + ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript); + sMovingNpcId = localId; + return FALSE; +} + +bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + const void *movementScript = (const void *)ScriptReadWord(ctx); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + ScriptMovement_StartObjectMovementScript(localId, mapNum, mapGroup, movementScript); + sMovingNpcId = localId; + return FALSE; +} + +static bool8 WaitForMovementFinish(void) +{ + return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); +} + +bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + if (localId != 0) + sMovingNpcId = localId; + sMovingNpcMapBank = gSaveBlock1Ptr->location.mapGroup; + sMovingNpcMapId = gSaveBlock1Ptr->location.mapNum; + SetupNativeScript(ctx, WaitForMovementFinish); + return TRUE; +} + +bool8 ScrCmd_waitmovement_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapBank; + u8 mapId; + + if (localId != 0) + sMovingNpcId = localId; + mapBank = ScriptReadByte(ctx); + mapId = ScriptReadByte(ctx); + sMovingNpcMapBank = mapBank; + sMovingNpcMapId = mapId; + SetupNativeScript(ctx, WaitForMovementFinish); + return TRUE; +} + +bool8 ScrCmd_removeobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + RemoveFieldObjectByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_removeobject_at(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + RemoveFieldObjectByLocalIdAndMap(objectId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_addobject(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + + show_sprite(objectId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_addobject_at(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + show_sprite(objectId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_setobjectxy(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_805F7C4(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, x, y); + return FALSE; +} + +bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetMapObjTemplateCoords(localId, x, y); + return FALSE; +} + +bool8 ScrCmd_moveobjectoffscreen(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + sub_805FE94(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_showobject_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 0); + return FALSE; +} + +bool8 ScrCmd_hideobject_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 1); + return FALSE; +} + +bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 priority = ScriptReadByte(ctx); + + sub_805F3A8(localId, mapNum, mapGroup, priority + 83); + return FALSE; +} + +bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + sub_805F400(localId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_faceplayer(struct ScriptContext *ctx) +{ + if (gMapObjects[gSelectedEventObject].active) + { + FieldObjectFaceOppositeDirection(&gMapObjects[gSelectedEventObject], + player_get_direction_lower_nybble()); + } + return FALSE; +} + +bool8 ScrCmd_turnobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 direction = ScriptReadByte(ctx); + + FieldObjectTurnByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, direction); + return FALSE; +} + +bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 movementType = ScriptReadByte(ctx); + + Overworld_SetMapObjTemplateMovementType(localId, movementType); + return FALSE; +} + +bool8 ScrCmd_createvobject(struct ScriptContext *ctx) +{ + u8 graphicsId = ScriptReadByte(ctx); + u8 v2 = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u32 y = VarGet(ScriptReadHalfword(ctx)); + u8 elevation = ScriptReadByte(ctx); + u8 direction = ScriptReadByte(ctx); + + sprite_new(graphicsId, v2, x, y, elevation, direction); + return FALSE; +} + +bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) +{ + u8 v1 = ScriptReadByte(ctx); + u8 direction = ScriptReadByte(ctx); + + sub_8069058(v1, direction); + return FALSE; +} + +bool8 ScrCmd_lockall(struct ScriptContext *ctx) +{ + if (is_c1_link_related_active()) + { + return FALSE; + } + else + { + ScriptFreezeMapObjects(); + SetupNativeScript(ctx, sub_8069590); + return TRUE; + } +} + +bool8 ScrCmd_lock(struct ScriptContext *ctx) +{ + if (is_c1_link_related_active()) + { + return FALSE; + } + else + { + if (gMapObjects[gSelectedEventObject].active) + { + LockSelectedMapObject(); + SetupNativeScript(ctx, sub_8069648); + } + else + { + ScriptFreezeMapObjects(); + SetupNativeScript(ctx, sub_8069590); + } + return TRUE; + } +} + +bool8 ScrCmd_releaseall(struct ScriptContext *ctx) +{ + u8 playerObjectId; + + HideFieldMessageBox(); + playerObjectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[playerObjectId]); + sub_80974D8(); + UnfreezeMapObjects(); + return FALSE; +} + +bool8 ScrCmd_release(struct ScriptContext *ctx) +{ + u8 playerObjectId; + + HideFieldMessageBox(); + if (gMapObjects[gSelectedEventObject].active) + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[gSelectedEventObject]); + playerObjectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[playerObjectId]); + sub_80974D8(); + UnfreezeMapObjects(); + return FALSE; +} + +bool8 ScrCmd_cmdC7(struct ScriptContext *ctx) +{ + gUnknown_20370DC = gUnknown_20370DA; + gUnknown_20370DA = ScriptReadByte(ctx); + return FALSE; +} + +bool8 ScrCmd_message(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + ShowFieldMessage(msg); + return FALSE; +} + +bool8 ScrCmd_cmdC8(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + sub_80F7974(msg); + CopyWindowToVram(GetStartMenuWindowId(), 1); + return FALSE; +} + +bool8 ScrCmd_cmdC9(struct ScriptContext *ctx) +{ + sub_80F7998(); + return FALSE; +} + +bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + ShowFieldAutoScrollMessage(msg); + return FALSE; +} + +bool8 ScrCmd_waitmessage(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsFieldMessageBoxHidden); + return TRUE; +} + +bool8 ScrCmd_closemessage(struct ScriptContext *ctx) +{ + HideFieldMessageBox(); + return FALSE; +} + +static bool8 WaitForAorBPress(void) +{ + if (gMain.newKeys & A_BUTTON) + return TRUE; + if (gMain.newKeys & B_BUTTON) + return TRUE; + + if (sub_806B93C(gUnknown_3005070) == TRUE) + { + u8 r4 = sub_806B96C(gUnknown_3005070); + sub_8069998(r4); + if (r4) + { + if (gUnknown_203ADFA != 2) + { + sub_80699F8(); + if (r4 < 9 || r4 > 10) + sub_8069964(); + else + { + sub_80699A4(); + sub_8069970(); + } + return TRUE; + } + } + } + if (sub_8112CAC() == 1 || gUnknown_203ADFA == 2) + { + if (gUnknown_20370AC == 120) + return TRUE; + else + gUnknown_20370AC++; + } + + return FALSE; +} + +static bool8 sub_806B93C(struct ScriptContext * ctx) +{ + const u8 * script = ctx->scriptPtr; + u8 nextCmd = *script; + if (nextCmd == 3) // return + { + script = ctx->stack[ctx->stackDepth - 1]; + nextCmd = *script; + } + if (nextCmd < 0x6B || nextCmd > 0x6C) // releaseall or release + return FALSE; + else + return TRUE; +} + +static u8 sub_806B96C(struct ScriptContext * ctx) +{ + if (gMain.heldKeys & DPAD_UP && gSpecialVar_Facing != 2) + return 1; + + if (gMain.heldKeys & DPAD_DOWN && gSpecialVar_Facing != 1) + return 2; + + if (gMain.heldKeys & DPAD_LEFT && gSpecialVar_Facing != 3) + return 3; + + if (gMain.heldKeys & DPAD_RIGHT && gSpecialVar_Facing != 4) + return 4; + + if (gMain.newKeys & L_BUTTON) + return 5; + + if (gMain.heldKeys & R_BUTTON) + return 6; + + if (gMain.heldKeys & START_BUTTON) + return 7; + + if (gMain.heldKeys & SELECT_BUTTON) + return 8; + + if (gMain.newKeys & A_BUTTON) + return 9; + + if (gMain.newKeys & B_BUTTON) + return 10; + + return 0; +} + +bool8 ScrCmd_waitbuttonpress(struct ScriptContext *ctx) +{ + gUnknown_3005070 = ctx; + + if (sub_8112CAC() == 1 || gUnknown_203ADFA == 2) + gUnknown_20370AC = 0; + SetupNativeScript(ctx, WaitForAorBPress); + return TRUE; +} + +bool8 ScrCmd_yesnobox(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + + if (ScriptMenu_YesNo(left, top) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_multichoice(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_multichoicedefault(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 defaultChoice = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_MultichoiceWithDefault(left, top, multichoiceId, ignoreBPress, defaultChoice) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_drawbox(struct ScriptContext *ctx) +{ + /*u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + + MenuDrawTextWindow(left, top, right, bottom);*/ + return FALSE; +} + +bool8 ScrCmd_multichoicegrid(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 numColumns = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_MultichoiceGrid(left, top, multichoiceId, ignoreBPress, numColumns) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_erasebox(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + + // MenuZeroFillWindowRect(left, top, right, bottom); + return FALSE; +} + +bool8 ScrCmd_drawboxtext(struct ScriptContext *ctx) +{ +// u8 left = ScriptReadByte(ctx); +// u8 top = ScriptReadByte(ctx); +// u8 multichoiceId = ScriptReadByte(ctx); +// u8 ignoreBPress = ScriptReadByte(ctx); + + /*if (Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + }*/ + return FALSE; +} + +bool8 ScrCmd_showmonpic(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + ScriptMenu_ShowPokemonPic(species, x, y); + PlayCry7(species, 0); + return FALSE; +} + +bool8 ScrCmd_hidemonpic(struct ScriptContext *ctx) +{ + bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); + + if (func == NULL) + return FALSE; + SetupNativeScript(ctx, func); + return TRUE; +} + +bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx) +{ + u8 v1 = ScriptReadByte(ctx); + + /* + if (v1) + sub_812FDA8(v1); + ShowContestWinner(); + ScriptContext1_Stop(); + return TRUE; + */ + + return FALSE; +} + +bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) +{ + u8 *ptr = (u8 *)ScriptReadWord(ctx); + if (ptr == NULL) + ptr = (u8 *)ctx->data[0]; + + sub_80F6E9C(); + sub_80F6EE4(0, 1); + AddTextPrinterParameterized(0, 6, ptr, 0, 1, 0, NULL); + return FALSE; +} + +bool8 ScrCmd_getbraillestringwidth(struct ScriptContext *ctx) +{ + u8 *ptr = (u8 *)ScriptReadWord(ctx); + if (ptr == NULL) + ptr = (u8 *)ctx->data[0]; + + gSpecialVar_0x8004 = GetStringWidth(6, ptr, -1); + return FALSE; +} + +bool8 ScrCmd_vmessage(struct ScriptContext *ctx) +{ + u32 v1 = ScriptReadWord(ctx); + + ShowFieldMessage((u8 *)(v1 - gVScriptOffset)); + return FALSE; +} + +u8 * const sScriptStringVars[] = +{ + gStringVar1, + gStringVar2, + gStringVar3, +}; + +bool8 ScrCmd_bufferspeciesname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 species = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gSpeciesNames[species]); + return FALSE; +} + +bool8 ScrCmd_bufferleadmonspeciesname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + + u8 *dest = sScriptStringVars[stringVarIndex]; + u8 partyIndex = GetLeadMonIndex(); + u32 species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); + StringCopy(dest, gSpeciesNames[species]); + return FALSE; +} + +bool8 ScrCmd_bufferpartymonnick(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); + StringGetEnd10(sScriptStringVars[stringVarIndex]); + return FALSE; +} + +bool8 ScrCmd_bufferitemname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + + CopyItemName(itemId, sScriptStringVars[stringVarIndex]); + return FALSE; +} + +extern const u8 gUnknown_83A72A0[]; +extern const u8 gUnknown_83A72A2[]; + +bool8 ScrCmd_bufferitemnameplural(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + CopyItemName(itemId, sScriptStringVars[stringVarIndex]); + if (itemId == ITEM_POKE_BALL && quantity >= 2) + StringAppend(sScriptStringVars[stringVarIndex], gUnknown_83A72A0); + else if (itemId >= ITEM_CHERI_BERRY && itemId < ITEM_ENIGMA_BERRY && quantity >= 2) + { + u16 strlength = StringLength(sScriptStringVars[stringVarIndex]); + if (strlength != 0) + { + u8 * endptr = sScriptStringVars[stringVarIndex] + strlength; + endptr[-1] = EOS; + StringAppend(sScriptStringVars[stringVarIndex], gUnknown_83A72A2); + } + } + + return FALSE; +} + +bool8 ScrCmd_bufferdecorationname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 decorId = VarGet(ScriptReadHalfword(ctx)); + +// StringCopy(sScriptStringVars[stringVarIndex], gDecorations[decorId].name); + return FALSE; +} + +bool8 ScrCmd_buffermovename(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 moveId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gMoveNames[moveId]); + return FALSE; +} + +bool8 ScrCmd_buffernumberstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 v1 = VarGet(ScriptReadHalfword(ctx)); + u8 v2 = CountDigits(v1); + + ConvertIntToDecimalStringN(sScriptStringVars[stringVarIndex], v1, 0, v2); + return FALSE; +} + +bool8 ScrCmd_bufferstdstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 index = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gStdStringPtrs[index]); + return FALSE; +} + +/* +bool8 ScrCmd_buffercontesttype(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 index = VarGet(ScriptReadHalfword(ctx)); + + sub_818E868(sScriptStringVars[stringVarIndex], index); + return FALSE; +} +*/ + +bool8 ScrCmd_bufferstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + const u8 *text = (u8 *)ScriptReadWord(ctx); + + StringCopy(sScriptStringVars[stringVarIndex], text); + return FALSE; +} + +bool8 ScrCmd_vloadword(struct ScriptContext *ctx) +{ + const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gVScriptOffset); + + StringExpandPlaceholders(gStringVar4, ptr); + return FALSE; +} + +bool8 ScrCmd_vbufferstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u32 addr = ScriptReadWord(ctx); + + const u8 *src = (u8 *)(addr - gVScriptOffset); + u8 *dest = sScriptStringVars[stringVarIndex]; + StringCopy(dest, src); + return FALSE; +} + +bool8 ScrCmd_bufferboxname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 boxId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], GetBoxNamePtr(boxId)); + return FALSE; +} + +bool8 ScrCmd_givemon(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 level = ScriptReadByte(ctx); + u16 item = VarGet(ScriptReadHalfword(ctx)); + u32 unkParam1 = ScriptReadWord(ctx); + u32 unkParam2 = ScriptReadWord(ctx); + u8 unkParam3 = ScriptReadByte(ctx); + + gSpecialVar_Result = ScriptGiveMon(species, level, item, unkParam1, unkParam2, unkParam3); + return FALSE; +} + +bool8 ScrCmd_giveegg(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = ScriptGiveEgg(species); + return FALSE; +} + +bool8 ScrCmd_setmonmove(struct ScriptContext *ctx) +{ + u8 partyIndex = ScriptReadByte(ctx); + u8 slot = ScriptReadByte(ctx); + u16 move = ScriptReadHalfword(ctx); + + ScriptSetMonMoveSlot(partyIndex, move, slot); + return FALSE; +} + +bool8 ScrCmd_checkpartymove(struct ScriptContext *ctx) +{ + u8 i; + u16 moveId = ScriptReadHalfword(ctx); + + gSpecialVar_Result = PARTY_SIZE; + for (i = 0; i < PARTY_SIZE; i++) + { + u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL); + if (!species) + break; + if (!GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) && MonKnowsMove(&gPlayerParty[i], moveId) == TRUE) + { + gSpecialVar_Result = i; + gSpecialVar_0x8004 = species; + break; + } + } + return FALSE; +} + +bool8 ScrCmd_givemoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + AddMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_takemoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + RemoveMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_checkmoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + gSpecialVar_Result = IsEnoughMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_showmoneybox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore && sub_81119D4(sub_809D6D4) != TRUE) + DrawMoneyBox(GetMoney(&gSaveBlock1Ptr->money), x, y); + return FALSE; +} + +bool8 ScrCmd_hidemoneybox(struct ScriptContext *ctx) +{ + /*u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx);*/ + + HideMoneyBox(); + return FALSE; +} + +bool8 ScrCmd_updatemoneybox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + ChangeAmountInMoneyBox(GetMoney(&gSaveBlock1Ptr->money)); + return FALSE; +} + +bool8 ScrCmd_showcoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + if (sub_81119D4(sub_809D6D4) != TRUE) + ShowCoinsWindow(GetCoins(), x, y); + return FALSE; +} + +bool8 ScrCmd_hidecoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + HideCoinsWindow(); + return FALSE; +} + +bool8 ScrCmd_updatecoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + PrintCoinsString(GetCoins()); + return FALSE; +} + +bool8 ScrCmd_trainerbattle(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_ConfigureTrainerBattle(ctx->scriptPtr); + return FALSE; +} + +bool8 ScrCmd_dotrainerbattle(struct ScriptContext *ctx) +{ + BattleSetup_StartTrainerBattle(); + return TRUE; +} + +bool8 ScrCmd_gotopostbattlescript(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_GetScriptAddrAfterBattle(); + return FALSE; +} + +bool8 ScrCmd_gotobeatenscript(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_GetTrainerPostBattleScript(); + return FALSE; +} + +bool8 ScrCmd_checktrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + ctx->comparisonResult = HasTrainerAlreadyBeenFought(index); + return FALSE; +} + +bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + SetTrainerFlag(index); + return FALSE; +} + +bool8 ScrCmd_cleartrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + ClearTrainerFlag(index); + return FALSE; +} + +bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) +{ + u16 species = ScriptReadHalfword(ctx); + u8 level = ScriptReadByte(ctx); + u16 item = ScriptReadHalfword(ctx); + + CreateScriptedWildMon(species, level, item); + return FALSE; +} + +bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) +{ + BattleSetup_StartScriptedWildBattle(); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemart(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreatePokemartMenu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemartdecoration(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreateDecorationShop1Menu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemartdecoration2(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreateDecorationShop2Menu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_playslotmachine(struct ScriptContext *ctx) +{ + u8 slotMachineIndex = VarGet(ScriptReadHalfword(ctx)); + + PlaySlotMachine(slotMachineIndex, c2_exit_to_overworld_1_continue_scripts_restart_music); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_setberrytree(struct ScriptContext *ctx) +{ +// u8 treeId = ScriptReadByte(ctx); +// u8 berry = ScriptReadByte(ctx); +// u8 growthStage = ScriptReadByte(ctx); +// +// if (berry == 0) +// PlantBerryTree(treeId, 0, growthStage, FALSE); +// else +// PlantBerryTree(treeId, berry, growthStage, FALSE); + return FALSE; +} + +bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx) +{ +// u16 value = VarGet(ScriptReadHalfword(ctx)); +// +// gSpecialVar_Result = GetPriceReduction(value); + return FALSE; +} + +bool8 ScrCmd_choosecontestmon(struct ScriptContext *ctx) +{ +// sub_81B9404(); + ScriptContext1_Stop(); + return TRUE; +} + + +bool8 ScrCmd_startcontest(struct ScriptContext *ctx) +{ +// sub_80F840C(); +// ScriptContext1_Stop(); +// return TRUE; + return FALSE; +} + +bool8 ScrCmd_showcontestresults(struct ScriptContext *ctx) +{ +// sub_80F8484(); +// ScriptContext1_Stop(); +// return TRUE; + return FALSE; +} + +bool8 ScrCmd_contestlinktransfer(struct ScriptContext *ctx) +{ +// sub_80F84C4(gSpecialVar_ContestCategory); +// ScriptContext1_Stop(); +// return TRUE; + return FALSE; +} + +bool8 ScrCmd_dofieldeffect(struct ScriptContext *ctx) +{ + u16 effectId = VarGet(ScriptReadHalfword(ctx)); + + sFieldEffectScriptId = effectId; + FieldEffectStart(sFieldEffectScriptId); + return FALSE; +} + +bool8 ScrCmd_setfieldeffectarg(struct ScriptContext *ctx) +{ + u8 argNum = ScriptReadByte(ctx); + + gFieldEffectArguments[argNum] = (s16)VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForFieldEffectFinish(void) +{ + if (!FieldEffectActiveListContains(sFieldEffectScriptId)) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitfieldeffect(struct ScriptContext *ctx) +{ + sFieldEffectScriptId = VarGet(ScriptReadHalfword(ctx)); + SetupNativeScript(ctx, WaitForFieldEffectFinish); + return TRUE; +} + +bool8 ScrCmd_setrespawn(struct ScriptContext *ctx) +{ + u16 healLocationId = VarGet(ScriptReadHalfword(ctx)); + + SetLastHealLocationWarp(healLocationId); + return FALSE; +} + +bool8 ScrCmd_checkplayergender(struct ScriptContext *ctx) +{ + gSpecialVar_Result = gSaveBlock2Ptr->playerGender; + return FALSE; +} + +bool8 ScrCmd_playmoncry(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u16 mode = VarGet(ScriptReadHalfword(ctx)); + + PlayCry7(species, mode); + return FALSE; +} + +bool8 ScrCmd_waitmoncry(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsCryFinished); + return TRUE; +} + +bool8 ScrCmd_setmetatile(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + u16 tileId = VarGet(ScriptReadHalfword(ctx)); + u16 v8 = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + if (!v8) + MapGridSetMetatileIdAt(x, y, tileId); + else + MapGridSetMetatileIdAt(x, y, tileId | 0xC00); + return FALSE; +} + +bool8 ScrCmd_opendoor(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + PlaySE(GetDoorSoundEffect(x, y)); + FieldAnimateDoorOpen(x, y); + return FALSE; +} + +bool8 ScrCmd_closedoor(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldAnimateDoorClose(x, y); + return FALSE; +} + +static bool8 IsDoorAnimationStopped(void) +{ + if (!FieldIsDoorAnimationRunning()) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitdooranim(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsDoorAnimationStopped); + return TRUE; +} + +bool8 ScrCmd_setdooropen(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldSetDoorOpened(x, y); + return FALSE; +} + +bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldSetDoorClosed(x, y); + return FALSE; +} + +bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx) +{ +// u8 v3 = ScriptReadByte(ctx); +// u16 v5 = VarGet(ScriptReadHalfword(ctx)); +// u16 v7 = VarGet(ScriptReadHalfword(ctx)); +// u16 v9 = VarGet(ScriptReadHalfword(ctx)); + + //ScriptAddElevatorMenuItem(v3, v5, v7, v9); + return FALSE; +} + +bool8 ScrCmd_showelevmenu(struct ScriptContext *ctx) +{ + /*ScriptShowElevatorMenu(); + ScriptContext1_Stop(); + return TRUE;*/ + return FALSE; +} + +bool8 ScrCmd_checkcoins(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr = GetCoins(); + return FALSE; +} + +bool8 ScrCmd_givecoins(struct ScriptContext *ctx) +{ + u16 coins = VarGet(ScriptReadHalfword(ctx)); + + if (GiveCoins(coins) == TRUE) + gSpecialVar_Result = 0; + else + gSpecialVar_Result = 1; + return FALSE; +} + +bool8 ScrCmd_takecoins(struct ScriptContext *ctx) +{ + u16 coins = VarGet(ScriptReadHalfword(ctx)); + + if (TakeCoins(coins) == TRUE) + gSpecialVar_Result = 0; + else + gSpecialVar_Result = 1; + return FALSE; +} + +bool8 ScrCmd_cmdCA(struct ScriptContext *ctx) +{ + sub_8069A20(); + return FALSE; +} + +bool8 ScrCmd_cmdCB(struct ScriptContext *ctx) +{ + sub_8069A2C(); + return FALSE; +} + +// This command will force the Pokémon to be obedient, you don't get to make it disobedient. +bool8 ScrCmd_setmonobedient(struct ScriptContext *ctx) +{ + bool8 obedient = TRUE; + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + SetMonData(&gPlayerParty[partyIndex], MON_DATA_OBEDIENCE, &obedient); + return FALSE; +} + +bool8 ScrCmd_checkmonobedience(struct ScriptContext *ctx) +{ + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OBEDIENCE, NULL); + return FALSE; +} + +bool8 ScrCmd_setmonmetlocation(struct ScriptContext *ctx) +{ + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + u8 location = ScriptReadByte(ctx); + + if (partyIndex < PARTY_SIZE) + SetMonData(&gPlayerParty[partyIndex], MON_DATA_MET_LOCATION, &location); + return FALSE; +} diff --git a/src/script.c b/src/script.c index 59ef4e579..d7246752c 100644 --- a/src/script.c +++ b/src/script.c @@ -19,7 +19,7 @@ enum }; EWRAM_DATA u8 gUnknown_20370A0 = 0; -EWRAM_DATA u8 *gUnknown_20370A4 = NULL; +EWRAM_DATA const u8 *gRAMScriptPtr = NULL; // ewram bss /*IWRAM_DATA*/ static u8 sScriptContext1Status; @@ -485,7 +485,7 @@ bool8 InitRamScript(u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 objec u8 *GetRamScript(u8 objectId, u8 *script) { struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data; - gUnknown_20370A4 = NULL; + gRAMScriptPtr = NULL; if (scriptData->magic != RAM_SCRIPT_MAGIC) return script; if (scriptData->mapGroup != gSaveBlock1Ptr->location.mapGroup) @@ -501,7 +501,7 @@ u8 *GetRamScript(u8 objectId, u8 *script) } else { - gUnknown_20370A4 = script; + gRAMScriptPtr = script; return scriptData->script; } } diff --git a/src/trainer_tower.c b/src/trainer_tower.c index b196c49f7..f4e18eee6 100644 --- a/src/trainer_tower.c +++ b/src/trainer_tower.c @@ -440,12 +440,12 @@ void sub_815DD44(void) if (gMapHeader.mapDataId - 0x129 > gUnknown_203F458->unk_0004.unk_0000.unk0) { gSpecialVar_Result = 3; - sub_8055D40(0x132); + SetCurrentMapLayout(0x132); } else { gSpecialVar_Result = gUnknown_203F458->unk_0004.unk_0008[gUnknown_203F458->unk_0000].unk_002; - sub_8055D40(gUnknown_847A284[gUnknown_203F458->unk_0000][gSpecialVar_Result]); + SetCurrentMapLayout(gUnknown_847A284[gUnknown_203F458->unk_0000][gSpecialVar_Result]); sub_815DDB0(); } } @@ -819,9 +819,9 @@ void sub_815E408(void) u16 itemId = gUnknown_847A2B4[gUnknown_203F458->unk_0004.unk_0008->unk_003]; if (gSaveBlock1Ptr->unkArray[gSaveBlock1Ptr->unkArrayIdx].unkA_0) gSpecialVar_Result = 2; - else if (sub_809A084(itemId, 1) == 1) + else if (AddBagItem(itemId, 1) == 1) { - sub_8099E90(itemId, gStringVar2); + CopyItemName(itemId, gStringVar2); gSaveBlock1Ptr->unkArray[gSaveBlock1Ptr->unkArrayIdx].unkA_0 = TRUE; gSpecialVar_Result = 0; } diff --git a/src/vs_seeker.c b/src/vs_seeker.c index 4d42f270d..579800576 100644 --- a/src/vs_seeker.c +++ b/src/vs_seeker.c @@ -65,7 +65,7 @@ struct VsSeekerStruct extern u16 gSpecialVar_LastTalked; extern struct MapObject gMapObjects[MAP_OBJECTS_COUNT]; -extern u8 gUnknown_3005074; +extern u8 gSelectedEventObject; // static declarations static EWRAM_DATA struct VsSeekerStruct *sVsSeeker = NULL; @@ -1012,7 +1012,7 @@ void sub_810CB90(void) sub_810CF54(&r4[r8]); // You are using this function incorrectly. Please consult the manual. sub_805FE7C(r4_2, gUnknown_8453F67[r4_2->mapobj_unk_18]); gSaveBlock1Ptr->trainerRematches[r4[r8].localId] = 0; - if (gUnknown_3005074 == sp0) + if (gSelectedEventObject == sp0) r4_2->animPattern = gUnknown_8453F67[r4_2->mapobj_unk_18]; else r4_2->animPattern = 0x08; |