Skip to content

Commit

Permalink
Sync mapjson/map.inc with pokeemerald
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed May 9, 2023
1 parent 566e716 commit af019d6
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 188 deletions.
1 change: 1 addition & 0 deletions data/maps.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "constants/global.h"
#include "constants/layouts.h"
#include "constants/map_types.h"
#include "constants/maps.h"
Expand Down
3 changes: 3 additions & 0 deletions include/constants/event_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
#define TRACKS_FOOT 1
#define TRACKS_BIKE_TIRE 2

#define OBJ_KIND_NORMAL 0
#define OBJ_KIND_CLONE 255 // Exclusive to FRLG

#define OBJ_EVENT_ID_PLAYER 0xFF
#define OBJ_EVENT_ID_CAMERA 0x7F

Expand Down
9 changes: 9 additions & 0 deletions include/constants/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@
#define BAG_BERRIES 4
#define BAG_KEYITEMS 5

#define CONNECTION_INVALID -1
#define CONNECTION_NONE 0
#define CONNECTION_SOUTH 1
#define CONNECTION_NORTH 2
#define CONNECTION_WEST 3
#define CONNECTION_EAST 4
#define CONNECTION_DIVE 5
#define CONNECTION_EMERGE 6

#endif // GUARD_CONSTANTS_GLOBAL_H
4 changes: 4 additions & 0 deletions include/constants/layouts.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef GUARD_CONSTANTS_LAYOUTS_H
#define GUARD_CONSTANTS_LAYOUTS_H

//
// DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json
//

#define LAYOUT_PETALBURG_CITY 1
#define LAYOUT_SLATEPORT_CITY 2
#define LAYOUT_MAUVILLE_CITY 3
Expand Down
4 changes: 4 additions & 0 deletions include/constants/map_groups.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef GUARD_CONSTANTS_MAP_GROUPS_H
#define GUARD_CONSTANTS_MAP_GROUPS_H

//
// DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/map_groups.json
//

// gMapGroup_TownsAndRoutes
#define MAP_PETALBURG_CITY (0 | (0 << 8))
#define MAP_SLATEPORT_CITY (1 | (0 << 8))
Expand Down
10 changes: 0 additions & 10 deletions include/global.fieldmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@

#define METATILE_ID(tileset, name) (METATILE_##tileset##_##name)

enum
{
CONNECTION_SOUTH = 1,
CONNECTION_NORTH,
CONNECTION_WEST,
CONNECTION_EAST,
CONNECTION_DIVE,
CONNECTION_EMERGE
};

typedef void (*TilesetCB)(void);

struct Tileset
Expand Down
144 changes: 96 additions & 48 deletions include/macros/map.inc
Original file line number Diff line number Diff line change
@@ -1,103 +1,151 @@
.macro map map_id
@ Most of the macros in this file are for arranging map event data, and are output by mapjson using data from each map's JSON file.

@ Takes a MAP constant and outputs the map group and map number as separate bytes
.macro map map_id:req
.byte \map_id >> 8 @ map group
.byte \map_id & 0xFF @ map num
.endm

.macro map_script type, address
@ Defines a map script. 'type' is any MAP_SCRIPT_* constant (see include/constants/map_scripts.h)
.macro map_script type:req, script:req
.byte \type
.4byte \address
.4byte \script
.endm

.macro map_script_2 word1, word2, address
.2byte \word1
.2byte \word2
.4byte \address
@ Defines an entry in a map script table (for either ON_WARP_INTO_MAP_TABLE or ON_FRAME_TABLE)
.macro map_script_2 var:req, compare:req, script:req
.2byte \var
.2byte \compare
.4byte \script
.endm

.macro object_event index, gfx, replacement, x, y, elevation, movement_type, x_radius, y_radius, trainer_type, sight_radius_tree_etc, script, event_flag
.byte \index, \gfx, \replacement, 0
.2byte \x
.2byte \y
.byte \elevation, \movement_type, ((\y_radius << 4) | \x_radius), 0
.2byte \trainer_type, \sight_radius_tree_etc
@ Defines an object event template for map data, to be used by a normal object. Mirrors the struct layout of ObjectEventTemplate in include/global.fieldmap.h
.macro object_event index:req, gfx:req, x:req, y:req, elevation:req, movement_type:req, x_radius:req, y_radius:req, trainer_type:req, sight_radius_tree_etc:req, script:req, event_flag:req
.byte \index
.byte \gfx
.byte OBJ_KIND_NORMAL
.space 1 @ Padding
.2byte \x, \y
.byte \elevation
.byte \movement_type
.byte ((\y_radius << 4) | \x_radius)
.space 1 @ Padding
.2byte \trainer_type
.2byte \sight_radius_tree_etc
.4byte \script
.2byte \event_flag
.2byte 0
.space 2 @ Padding
inc _num_npcs
.endm

.macro warp_def x, y, elevation, warp, map_id
@ Defines an object event template for map data, to be used by a clone object. Mirrors the struct layout of ObjectEventTemplate in include/global.fieldmap.h
@ NOTE: The handling for this type of event does not exist in Ruby/Sapphire by default; it is exclusive to FRLG.
.macro clone_event index:req, gfx:req, x:req, y:req, target_local_id:req, target_map_id:req
.byte \index
.byte \gfx
.byte OBJ_KIND_CLONE
.space 1 @ Padding
.2byte \x, \y
.byte \elevation, \warp
.byte \target_local_id
.space 3 @ Padding
.2byte \target_map_id & 0xFF @ map num
.2byte \target_map_id >> 8 @ map group
.space 8 @ Padding
inc _num_npcs
.endm

@ Defines a warp event for map data. Mirrors the struct layout of WarpEvent in include/global.fieldmap.h
.macro warp_def x:req, y:req, elevation:req, warpId:req, map_id:req
.2byte \x, \y
.byte \elevation
.byte \warpId
.byte \map_id & 0xFF @ map num
.byte \map_id >> 8 @ map group
inc _num_warps
.endm

.macro coord_event x, y, elevation, trigger, index, script
@ Defines a coord event for map data. Mirrors the struct layout of CoordEvent in include/global.fieldmap.h
.macro coord_event x:req, y:req, elevation:req, var:req, varValue:req, script:req
.2byte \x, \y
.byte \elevation, 0
.2byte \trigger, \index, 0
.byte \elevation
.space 1 @ Padding
.2byte \var
.2byte \varValue
.space 2 @ Padding
.4byte \script
inc _num_traps
.endm

.macro coord_weather_event x, y, elevation, weather
.2byte \x, \y
.byte \elevation, 0
.2byte \weather
.2byte 0, 0
.4byte 0
inc _num_traps
@ Defines a weather coord event for map data. Any coord event is treated as a weather coord event if its script is NULL
.macro coord_weather_event x:req, y:req, elevation:req, weather:req
coord_event \x, \y, \elevation, \weather, 0, NULL
.endm

.macro bg_event x, y, elevation, kind, arg6, arg7, arg8
@ Defines a generic background event for map data. Mirrors the struct layout of BgEvent in include/global.fieldmap.h
@ 'kind' is any BG_EVENT_* constant (see include/constants/event_bg.h).
@ 'arg6' and 'arg7' are used differently depending on the bg event type. See macros below
.macro bg_event x:req, y:req, elevation:req, kind:req, arg6:req, arg7
.2byte \x, \y
.byte \elevation, \kind
.2byte 0
.if \kind < 5
.4byte \arg6
.byte \elevation
.byte \kind
.space 2 @ Padding
.if \kind != BG_EVENT_HIDDEN_ITEM
.4byte \arg6
.else
.2byte \arg6
.byte \arg7, \arg8
.2byte \arg6
.2byte \arg7
.endif
inc _num_signs
.endm

.macro bg_hidden_item_event x, y, height, item, flag
bg_event \x, \y, \height, 7, \item, ((\flag) - FLAG_HIDDEN_ITEMS_START), 0
@ Defines a background sign event for map data. 'facing_dir' is any of the BG_EVENT_PLAYER_FACING_* constants (see include/constants/event_bg.h)
.macro bg_sign_event x:req, y:req, elevation:req, facing_dir:req, script:req
bg_event \x, \y, \elevation, \facing_dir, \script
.endm

.macro bg_secret_base_event x, y, height, secret_base_id
bg_event \x, \y, \height, 8, \secret_base_id, 0, 0
.endm
@ Defines a background hidden item event for map data
.macro bg_hidden_item_event x:req, y:req, elevation:req, item:req, flag:req
bg_event \x, \y, \elevation, BG_EVENT_HIDDEN_ITEM, \item, ((\flag) - FLAG_HIDDEN_ITEMS_START)
.endm

@ Defines a background secret base event for map data
.macro bg_secret_base_event x:req, y:req, elevation:req, secret_base_id:req
bg_event \x, \y, \elevation, BG_EVENT_SECRET_BASE, \secret_base_id
.endm

.macro map_events npcs, warps, traps, signs
@ Defines the table of event data for a map. Mirrors the struct layout of MapEvents in include/global.fieldmap.h
.macro map_events npcs:req, warps:req, traps:req, signs:req
.byte _num_npcs, _num_warps, _num_traps, _num_signs
.4byte \npcs, \warps, \traps, \signs
reset_map_events
.endm

@ Resets the event counters used to track how many events a map has. Run when the events table is created by map_events
.macro reset_map_events
.set _num_npcs, 0
.set _num_warps, 0
.set _num_traps, 0
.set _num_signs, 0
.endm

@ Initialize the event counters for the first map
reset_map_events


.equiv connection_down, 1
.equiv connection_up, 2
.equiv connection_left, 3
.equiv connection_right, 4
.equiv connection_dive, 5
.equiv connection_emerge, 6
@ Directions for connecting maps
@ The map.json files will only have e.g. "down" as direction data, and this will be appended to "connection_" by the connection macro
.equiv connection_down, CONNECTION_SOUTH
.equiv connection_up, CONNECTION_NORTH
.equiv connection_left, CONNECTION_WEST
.equiv connection_right, CONNECTION_EAST
.equiv connection_dive, CONNECTION_DIVE
.equiv connection_emerge, CONNECTION_EMERGE

.macro connection direction, offset, map, filler
.4byte connection_\direction
@ Defines a map connection. Mirrors the struct layout of MapConnection in include/global.fieldmap.h
.macro connection direction:req, offset:req, map:req
.byte connection_\direction
.space 3 @ Padding
.4byte \offset
map \map
.space 2
.space 2 @ Padding
.endm
Loading

0 comments on commit af019d6

Please sign in to comment.