Collision map file: Difference between revisions
Paths |
→Tile data: add tilemap offset |
||
(3 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
= File format = | = File format = | ||
<syntaxhighlight lang="c"> | |||
struct collision_map_file { | |||
/* offset 0x00 */ char magic[4]; // "HP" followed by two null bytes | |||
// Byte offset from start of this struct to the tile_data struct | |||
/* offset 0x04 */ u32 offsetToTileData; | |||
// Byte offset from start of this struct to the zone_data struct | |||
/* offset 0x08 */ u32 offsetToZones; | |||
// Byte offset from start of this struct to the PathData struct | |||
/* offset 0x0c */ u32 offsetToPaths; | |||
// Byte offset from start of this struct to the NavMesh struct | |||
/* offset 0x10 */ u32 offsetToNavmesh; | |||
}; | |||
</syntaxhighlight> | |||
= Tile data = | = Tile data = | ||
Line 35: | Line 30: | ||
u16 width; | u16 width; | ||
u16 height; | u16 height; | ||
// pixel position of tilemap on the collision map (for camera) | |||
i16 tilemap_offset_x; | |||
i16 tilemap_offset_y; | |||
tile[height*width] tiles; | tile[height*width] tiles; | ||
}; | }; | ||
Line 128: | Line 125: | ||
* 0xd0: Start searching | * 0xd0: Start searching | ||
= | = Navigation mesh = | ||
'''TODO''': This description is for Boktai 1 only. The navigation mesh data (may?) have changed in Boktai 2. | |||
The navigation mesh is used to guide NPCs between arbitrary points on the map. A navigation mesh contains three data structures: | |||
* A list of ''rectangles'' (<code>NavRect</code>). Each rectangle is axis-aligned and free of obstacles. For any two points within the same rectangle, the shortest path between them is a straight line. Every walkable tile on the map should be covered by at least one NavRect. | |||
* A list of ''portals'' (<code>NavPortal</code>). NavRects always have at least one tile of overlap with adjacent NavRects, and at the center of each overlapping area there is a portal. | |||
* A ''distance map'' containing the distance between each possible pair of portals (as calculated by a path-finding algorithm). | |||
For example, here is an image of Boktai 1's <code>st01_02a</code>, the exterior portion of the entrance to Bloodrust Mansion. A subset of NavRects are shown as green rectangles. Note how there is one tile of overlap between the long vertical road, and the small horizontal paths sticking out of the road. At the center of each overlap is a blue marker, representing a portal: | |||
[[File:St01_00a_navmesh.png]] | |||
<syntaxhighlight lang="c"> | |||
struct NavMesh { | |||
// Number of elements in the rects array | |||
/* offset 0x00*/ u16 countRects; | |||
/* offset 0x02*/ u16 countPortals; | |||
/* offset 0x04*/ u16 countDistanceMap; | |||
// Byte offset from start of this struct to the rects array | |||
/* offset 0x08*/ u32 offsetToRects; | |||
/* offset 0x0c*/ u32 offsetToPortals; | |||
/* offset 0x10*/ u32 offsetToDistanceMap; | |||
NavRect rects[]; | |||
NavPortal portals[]; | |||
// The distance map is stored in a compressed form: On a logical level, it is | |||
// a matrix with countPortal rows and countPortal columns, where each element | |||
// in the matrix is the distance between the two portals. | |||
// However, since the distance between two points is the same in either | |||
// direction, we only store the top-right half of the matrix (the bottom-left | |||
// half is a mirror image). And since the distance between a portal and | |||
// itself is zero, we don't store the diagonal either. | |||
// If two portals are connected via a straight line, then the distance is just | |||
// sqrt((x1-x2)^2 + (y1-y2)^2)). If there is no path at all between two | |||
// portals, then the distance should be set to 0xffff. | |||
u16 distanceMap[]; | |||
}; | |||
struct NavRect { | |||
// 1 tile = 1 | |||
/* offset 0x00 */ u8 minX; | |||
/* offset 0x01 */ u8 minY; | |||
/* offset 0x02 */ u8 maxX; | |||
/* offset 0x03 */ u8 maxY; | |||
// Indices into NavMesh.portals. At most 12 portals per rect, unused elements | |||
// in this array must be at the end of the array, and set to 0xff. | |||
u8 portals[12]; | |||
}; | |||
struct NavPortal { | |||
// 1 tile = 0x100 | |||
/* offset 0x00 */ u16 x; | |||
/* offset 0x02 */ u16 y; | |||
/* offset 0x04 */ u16 unknown_0x04; | |||
// Indices into NavMesh.rects. At most 6 rects per portal, unused elements | |||
// in this array must be at the end of the array, and set to 0xff. | |||
/* offset 0x06 */ u8 rects[6]; | |||
}; | |||
</syntaxhighlight> | |||
To retrieve the distance between portals ''i'' and ''j'': | |||
<syntaxhighlight lang="c"> | |||
u16 GetDistance(u16* distanceMap, u16 countPortals, int i, int j) | |||
{ | |||
if (i == j) { | |||
return 0; | |||
} | |||
if (j < i) { | |||
// Ensure i < j | |||
std::swap(i, j); | |||
} | |||
int index = i*countPortals + j - ((i+2)*(i+1) >> 1); | |||
return distanceMap[index]; | |||
} | |||
</syntaxhighlight> | |||
= See also = | = See also = | ||
* [[Collision map files (Boktai 1)]] | * [[Collision map files (Boktai 1)]] | ||
* [[Collision map files (Boktai 2)]] | |||
[[Category:Documentation]] [[Category:File formats]] | [[Category:Documentation]] [[Category:File formats]] | ||
[[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]] | [[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]] |