/* SPDX-License-Identifier: MIT */ /* * konrmmap.h * * Copyright (c) 2026 KonAki * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef KONRMMAP_H #define KONRMMAP_H #include #ifdef __cplusplus extern "C" { #endif /*** definition ***/ /* what mzmap writes for a map of an RPG Maker MV or MZ game: all of it const data, so it can sit in the program as it is. the structs are only ever read. the event scripts are not in here, a page names the label of its script in the konscript the converter wrote next to it ("m3e12p1" is map 3, event 12, page 1) */ #define KON_RM_LAYERS 6 /* four tile layers, then shadows, then regions */ typedef struct kon_rmPage { /* conditions, each used only when its flag is 1 */ uint8_t hasSwitch1, hasSwitch2, hasVariable, hasSelfSwitch, hasItem, hasActor; char selfSwitch; /* 'A' to 'D' */ int switch1, switch2, variable, variableValue, item, actor; /* a character sheet, or a tile of the map's tileset when tileId is not 0 */ const char *characterName; int characterIndex, direction, pattern, tileId; uint8_t moveType; /* 0 fixed, 1 random, 2 approach, 3 custom */ uint8_t moveSpeed, moveFrequency; uint8_t priority; /* 0 under the characters, 1 same as them, 2 over them */ uint8_t trigger; /* 0 action button, 1 player touch, 2 event touch, 3 autorun, 4 parallel */ uint8_t walkAnime, stepAnime, directionFix, through; uint8_t routeRepeat, routeSkippable, routeWait; const char *script; /* the custom move route, a command and its numbers after each other: code, count, count numbers. a count of 0 for a command that had text, which is not kept. empty for none */ const int32_t *route; int routeSize; } kon_rmPage_t; typedef struct kon_rmEvent { int id; const char *name; int x, y; const kon_rmPage_t *pages; int pageCount; } kon_rmEvent_t; typedef struct kon_rmEncounter { int troopId; int weight; const int *regions; /* where it can happen, none means everywhere */ int regionCount; } kon_rmEncounter_t; typedef struct kon_rmAudio { const char *name; /* "" for none */ int volume, pitch, pan; } kon_rmAudio_t; typedef struct kon_rmMap { int id; int width, height; int tilesetId; const uint16_t *tiles; /* the layers one after the other, each width * height, row by row */ const char *displayName; const char *note; int scrollType; /* 0 none, 1 loops up and down, 2 loops left and right, 3 both */ int disableDashing; int autoplayBgm, autoplayBgs; kon_rmAudio_t bgm, bgs; const char *parallaxName; int parallaxLoopX, parallaxLoopY, parallaxSx, parallaxSy, parallaxShow; int encounterStep; const kon_rmEncounter_t *encounters; int encounterCount; const kon_rmEvent_t *events; int eventCount; } kon_rmMap_t; typedef struct kon_rmTileset { int id; int mode; /* 0 for the world map, 1 for the others */ const char *names[9]; /* A1 to A5, then B to E, "" when there is none */ const uint16_t *flags; int flagCount; } kon_rmTileset_t; typedef struct kon_rmSystem { const char *title; int startMapId, startX, startY; const int *party; int partyCount; int switchCount, variableCount; int optFollowers, optTransparent; int windowTone[3]; } kon_rmSystem_t; /*** pages ***/ /* what a page needs to know about the game to be switched on. any of them can be NULL, which reads as off, 0 and no */ typedef struct kon_rmState { int (*switchOn)(int id, void *user); int (*variable)(int id, void *user); int (*selfSwitch)(int mapId, int eventId, char letter, void *user); int (*hasItem)(int id, void *user); int (*hasActor)(int id, void *user); void *user; } kon_rmState_t; /* the page an event is showing, like RPG Maker picks it: the last one that has all its conditions, counted from the end. returns -1 when none of them do, then the event is not on the map at all */ int kon_rmEventPage(const kon_rmEvent_t *event, int mapId, const kon_rmState_t *state); /*** tiles ***/ /* layer is 0 to 5, the four tile layers, the shadows and the regions. 0 outside of the map or for a layer that is not there */ int kon_rmTile(const kon_rmMap_t *map, int layer, int x, int y); /*** walking ***/ /* the directions RPG Maker uses, the numbers on a keypad */ #define KON_RM_DOWN 2 #define KON_RM_LEFT 4 #define KON_RM_RIGHT 6 #define KON_RM_UP 8 /* the flags of a tile in a tileset, the tile layers of the map read from the top one down. a tile past the end of the flags has none. these are RPG Maker's own bits, in kon_rmFlags and below */ #define KON_RM_FLAG_NO_EFFECT 0x10 /* a star in the editor: this tile does not decide whether you can walk */ #define KON_RM_FLAG_LADDER 0x20 #define KON_RM_FLAG_BUSH 0x40 #define KON_RM_FLAG_COUNTER 0x80 #define KON_RM_FLAG_DAMAGE 0x100 int kon_rmFlags(const kon_rmTileset_t *tileset, int tile); /* is x, y inside the map, once a map that loops has wrapped it. loops are the map's scroll type */ int kon_rmValid(const kon_rmMap_t *map, int x, int y); /* wraps x or y for a map that loops that way, other positions stay as they are */ int kon_rmRoundX(const kon_rmMap_t *map, int x); int kon_rmRoundY(const kon_rmMap_t *map, int y); /* can something on x, y leave this tile going dir, as far as the tiles say. no events and no outside of the map here */ int kon_rmPassable(const kon_rmMap_t *map, const kon_rmTileset_t *tileset, int x, int y, int dir); /* can it step from x, y to the next tile in dir: the next tile is on the map, and both tiles let it through, the one it is on on the way out and the next on the way in. what an event on the tile would say about it is for the game to ask */ int kon_rmCanWalk(const kon_rmMap_t *map, const kon_rmTileset_t *tileset, int x, int y, int dir); /* the terrain tag a tile is marked with in the editor, 0 for none, 0 outside of the map. the top layer that has one wins */ int kon_rmTerrainTag(const kon_rmMap_t *map, const kon_rmTileset_t *tileset, int x, int y); /* the region painted on x, y, 0 for none */ int kon_rmRegion(const kon_rmMap_t *map, int x, int y); /* 1 when any of the layers of that tile has the flag, 0 outside of the map */ int kon_rmHasFlag(const kon_rmMap_t *map, const kon_rmTileset_t *tileset, int x, int y, int flag); #ifdef __cplusplus } #endif #endif