45#ifndef NILOREA_ISOMETRIC_ENGINE
46#define NILOREA_ISOMETRIC_ENGINE
80#define ISO_EDGE_W (1 << 0)
82#define ISO_EDGE_N (1 << 1)
84#define ISO_EDGE_E (1 << 2)
86#define ISO_EDGE_S (1 << 3)
88#define ISO_NUM_EDGE_MASKS 16
91#define ISO_CORNER_NW (1 << 0)
93#define ISO_CORNER_NE (1 << 1)
95#define ISO_CORNER_SE (1 << 2)
97#define ISO_CORNER_SW (1 << 3)
99#define ISO_NUM_CORNER_MASKS 16
101#define ISO_NUM_MASKS (ISO_NUM_EDGE_MASKS + ISO_NUM_CORNER_MASKS)
108#define ISO_PROJ_CLASSIC 0
110#define ISO_PROJ_ISOMETRIC 1
112#define ISO_PROJ_MILITARY 2
114#define ISO_PROJ_STAGGERED 3
116#define ISO_NUM_PROJECTIONS 4
120#define ISO_PROJ_STEEP ISO_PROJ_ISOMETRIC
122#define ISO_PROJ_WIDE ISO_PROJ_STAGGERED
129#define ISO_MAX_SEGMENTS_PER_TILE 2
284void iso_corner_to_screen(
const ISO_MAP* map,
int cx,
int cy,
float fh,
float cam_x,
float cam_y,
float zoom,
float* sx,
float* sy);
323ASTAR_GRID* iso_map_to_astar_grid(
const ISO_MAP* map,
int max_height_diff,
int start_x,
int start_y);
503#include <allegro5/allegro.h>
504#include <allegro5/allegro_primitives.h>
505#include <allegro5/allegro_font.h>
530 ALLEGRO_BITMAP** overlay_bitmaps,
531 int num_overlay_tiles,
568 ALLEGRO_BITMAP** masks,
645int create_empty_map(
MAP** map,
const char* name,
int XSIZE,
int YSIZE,
int TILEW,
int TILEH,
int nbmaxobjects,
int nbmaxgroup,
int nbmaxanims,
int nbtiles,
int nbanims);
647int set_value(
MAP* map,
int type,
int x,
int y,
int value);
651int ScreenToMap(
int mx,
int my,
int* Tilex,
int* Tiley, ALLEGRO_BITMAP* mousemap);
657int draw_map(
MAP* map, ALLEGRO_BITMAP* bmp,
int destx,
int desty,
int mode);
static ALLEGRO_BITMAP * transition_tiles[8][(16+16)]
static ALLEGRO_BITMAP * tile_bitmaps[8]
Grid structure holding walkability, costs, and dimensions.
int bottom
segment bottom height (primary sort key)
char * quests_group_names
as for previous:char *object_group_names
float fz
height in map units (elevation)
int X
X move in pixel for drawing.
char * sounds_group_names
as for previous:char *object_group_names
int TILEW
size X of tiles of the map (in pixel)
int * neighbor_heights_west
Heights from west neighbor chunk's east edge [height], NULL = boundary.
float fy
fractional map Y position
int lower_tile
terrain index for wall/side faces (-1 = use tile's terrain layer)
int * ability
walkability per cell [height * width] (WALK/SWIM/BLCK)
int height
map height in tiles (Y axis)
float occluded_alpha
overlay alpha when behind tiles [0..1], 0=hidden, 0.35=ghost, 1=always visible
int ability
ability of the tile (walking, swimming, blocking, killing ?)
ALLEGRO_BITMAP * colortile
default full colored background tile
int upper_tile
terrain index for top face (-1 = use tile's terrain layer)
int neighbor_top_se
top height of SE neighbor (0 if absent/boundary)
float tile_lift
vertical pixel offset per height unit
float zoom_min
minimum allowed zoom
int * neighbor_heights_east
Heights from east neighbor chunk's west edge [height], NULL = boundary.
int draw_sw
1 if SW edge (S→W, bottom-left) should be drawn
ALLEGRO_COLOR bgcolor
color of the bg
int neighbor_top_sw
top height of SW neighbor (0 if absent/boundary)
float angle_deg
current projection angle in degrees
int smooth_height
0 = CUT mode (cliff walls), 1 = SMOOTH mode (per-corner slopes)
int tilenumber
ident of the tile in the MAP->tile library
float half_w
half-width of a tile in pixels (horizontal extent)
int count
0..ISO_MAX_SEGMENTS_PER_TILE
char * name
Name of the map ( used for linking between two map )
int ptanchorY
Y starting cell for drawing.
int bottom
lower height bound (inclusive), must be < top
int hover_mx
hovered tile X (-1 = none)
int max_height
maximum allowed height value
int ptanchorX
X starting cell for drawing.
int top
segment top height
float sprite_h
entity height in world units for occlusion (derived from sprite hot_y)
int seg_idx
segment index within tile (0..count-1)
int draw_nw
1 if NW edge (N→W, top-left) should be drawn
int underside
1 if underside face should be drawn
int neighbor_top_ne
top height of NE neighbor (0 if absent/boundary)
float occlude_clip_y
OUTPUT: screen Y of top occluder north vertex (for cross-chunk clip fallback)
int TILEH
size Y of tiles of the map (in pixel)
char * object_group_names
name of the main group of the (kind of) library of objects, filled by zero else, size iz limited to 5...
int num_terrains
number of terrain types used
float * dynamic_light_map
Per-tile dynamic light accumulation buffer.
int top
upper height bound, must be > bottom
CELL * grid
Grid of each cell of the map.
float half_h
half-height of a tile in pixels (vertical extent)
int * overlay
overlay tile index per cell [height * width], 0 = none.
float lerp_speed
interpolation speed factor (default 3.0)
int neighbor_top_nw
top height of NW neighbor (0 if absent/boundary)
float fx
fractional map X position
void * user_data
user data passed to draw callback
int * neighbor_heights_south
Heights from south neighbor chunk's north edge [width], NULL = boundary.
int * terrain
terrain type per cell [height * width], indices 0..num_terrains-1
N_ISO_OBJECT_DRAW_FN draw
draw callback
int YSIZE
size Y of the grid (nbYcell)
int XSIZE
size X of the grid (nbXcell)
float zoom_max
maximum allowed zoom
int * neighbor_heights_north
Heights from north neighbor chunk's south edge [width], NULL = boundary.
float height_tint_intensity
0.0 = no tint, 0.3 = subtle, 1.0 = full range.
float zoom
zoom factor (1.0 = no zoom)
int is_occluded
OUTPUT: set to 1 if behind tiles during last iso_map_draw() call.
char * anim_group_names
as for previous:char *object_group_names
int music
ident of the music on the tile
int draw_se
1 if SE edge (E→S, bottom-right) should be drawn
int objectnumber
ident of the object in the MAP->object library
int * heightmap
height value per cell [height * width], 0..max_height
float y
camera Y offset (world units, pre-zoom)
float ambient_r
Global ambient color (day/night + dark place tinting).
int width
map width in tiles (X axis)
int show_grid
1 = draw grid overlay
float target_angle
target angle for smooth interpolation (degrees)
int draw_ne
1 if NE edge (N→E, top-right) should be drawn
int Y
Y move in pixel for drawing.
ISO_TILE_SEGMENTS * segments
Per-cell height segments.
float sprite_half_w
entity half-width in screen pixels for horizontal occlusion test
ALLEGRO_BITMAP * mousemap
Map for mouse collision between mouse pointer and map.
int draw_underside
1 if floating segment underside border should be drawn
int smooth_slope_max
max height diff rendered as slope (default 1)
int hover_my
hovered tile Y (-1 = none)
float x
camera X offset (world units, pre-zoom)
ISO_PROJECTION proj
current projection parameters
ALLEGRO_COLOR wirecolor
color of wire
void iso_map_set_height(ISO_MAP *map, int mx, int my, int h)
set height for a cell (bounds-checked, clamped)
int save_map(MAP *map, char *filename)
Save the map.
void iso_map_set_projection_custom(ISO_MAP *map, float half_w, float half_h, float tile_lift)
set custom projection parameters directly
void iso_map_smooth_corner_heights(const ISO_MAP *map, int mx, int my, float *h_n, float *h_e, float *h_s, float *h_w)
compute smooth corner heights with slope clamping (for rendering)
int get_value(MAP *map, int type, int x, int y)
Get the tilenumber of a cell.
ISO_MAP * iso_map_new(int width, int height, int num_terrains, int max_height)
create a new height-aware ISO_MAP with given dimensions
float iso_diamond_dist(int px, int py, int tile_w, int tile_h)
distance from pixel to diamond edge (0 at edge, 1 at center)
int iso_map_set_segments(ISO_MAP *map, int mx, int my, const ISO_TILE_SEGMENT *segs, int count)
set per-tile segments on an ISO_MAP.
int draw_map(MAP *map, ALLEGRO_BITMAP *bmp, int destx, int desty, int mode)
Draw the map using its coordinate on the specified bitmap.
void n_iso_camera_zoom(N_ISO_CAMERA *cam, float dz, float mouse_x, float mouse_y)
Zoom the camera toward a screen-space point (e.g.
void n_iso_camera_center_on(N_ISO_CAMERA *cam, float world_x, float world_y, int screen_w, int screen_h)
Center the camera so that a world point is at screen center.
int iso_map_save(const ISO_MAP *map, const char *filename)
save ISO_MAP to binary file (chunk-based format)
int iso_map_should_transition_smooth(const ISO_MAP *map, int mx1, int my1, int mx2, int my2)
check if terrain transition should render between two cells (height-aware)
void iso_corner_to_screen(const ISO_MAP *map, int cx, int cy, float fh, float cam_x, float cam_y, float zoom, float *sx, float *sy)
Project a tile corner to screen coordinates (canonical formula).
int load_map(MAP **map, char *filename)
Load the map.
int camera_to_map(MAP **map, int tx, int ty, int x, int y)
Center Map on given map coordinate, with x & y offset.
void iso_map_lerp_projection(ISO_MAP *map, float dt)
smoothly interpolate current projection angle toward target (call every frame)
#define ISO_MAX_SEGMENTS_PER_TILE
Max height segments per tile (ground + one elevated structure).
void iso_mask_tile_to_diamond(ALLEGRO_BITMAP *bmp, int tile_w, int tile_h)
Mask a tile bitmap to the isometric diamond shape.
ISO_VISIBLE_EDGES iso_map_get_visible_edges(const ISO_MAP *map, int mx, int my)
Compute which diamond edges of tile (mx, my) need a height border.
ISO_MAP * iso_map_load(const char *filename)
load ISO_MAP from binary file
void n_iso_camera_free(N_ISO_CAMERA **cam)
Free a camera and set the pointer to NULL.
int iso_map_build_draw_order(const ISO_MAP *map, ISO_DRAW_ENTRY *out, int max_entries)
Build the draw order for segment-sorted rendering.
int iso_map_should_transition(const ISO_MAP *map, int mx1, int my1, int mx2, int my2)
check if terrain blending should occur between two adjacent cells
const char * iso_projection_name(int preset)
get the display name for a projection preset
void n_iso_camera_follow(N_ISO_CAMERA *cam, float target_x, float target_y, int screen_w, int screen_h, float smoothing, float dt)
Smoothly follow a world-space target (camera lerp).
void iso_map_set_ability(ISO_MAP *map, int mx, int my, int ab)
set ability for a cell (bounds-checked)
ISO_VISIBLE_EDGES iso_map_get_visible_edges_segment(const ISO_MAP *map, int mx, int my, int seg_idx)
Compute per-segment edge visibility for height border rendering.
int iso_map_get_terrain(const ISO_MAP *map, int mx, int my)
get terrain type for a cell (bounds-checked)
int camera_to_scr(MAP **map, int x, int y)
Center Map on given screen coordinate.
void iso_map_calc_transitions_full(const ISO_MAP *map, int mx, int my, int *edge_bits, int *corner_bits)
compute per-terrain transition bitmasks with height filtering (Article 934).
int iso_map_get_ability(const ISO_MAP *map, int mx, int my)
get ability for a cell (bounds-checked)
void iso_map_draw(const ISO_MAP *map, ALLEGRO_BITMAP **tile_bitmaps, ALLEGRO_BITMAP ***transition_tiles, int num_masks, ALLEGRO_BITMAP **overlay_bitmaps, int num_overlay_tiles, float cam_px, float cam_py, float zoom, int screen_w, int screen_h, int player_mode, N_ISO_OBJECT *objects, int num_objects)
Draw the full ISO_MAP with height, transitions, overlays, cliff walls, hover, and grid.
int set_value(MAP *map, int type, int x, int y, int value)
Set the tilenumber of a cell.
void iso_map_to_screen(const ISO_MAP *map, int mx, int my, int h, float *screen_x, float *screen_y)
convert map tile coordinates to screen pixel coordinates
void iso_map_calc_transitions(const ISO_MAP *map, int mx, int my, int *edge_bits, int *corner_bits)
compute terrain transition bitmasks for a cell (Article 934)
void iso_map_set_projection(ISO_MAP *map, int preset, float tile_width)
set projection preset and snap to it immediately
void n_iso_camera_screen_to_world(const N_ISO_CAMERA *cam, float sx, float sy, float *wx, float *wy)
Convert screen pixel coordinates to world coordinates.
int ScreenToMap(int mx, int my, int *Tilex, int *Tiley, ALLEGRO_BITMAP *mousemap)
Convert screen coordinate to map coordinate.
void iso_map_to_screen_f(const ISO_MAP *map, float fmx, float fmy, float h, float *screen_x, float *screen_y)
convert map tile coordinates to screen pixel coordinates (float version)
void iso_map_free(ISO_MAP **map)
free an ISO_MAP and set the pointer to NULL
int iso_is_in_diamond(int px, int py, int tile_w, int tile_h)
test if pixel (px,py) is inside the isometric diamond of size tile_w x tile_h
void iso_generate_transition_tiles(ALLEGRO_BITMAP ***tiles, ALLEGRO_BITMAP **masks, ALLEGRO_BITMAP **tile_bitmaps, int num_terrains, int tile_w, int tile_h)
Pre-composite transition tiles (terrain texture * alpha mask).
void iso_map_set_projection_target(ISO_MAP *map, int preset)
set target projection preset for smooth interpolation via iso_map_lerp_projection
void iso_map_set_terrain(ISO_MAP *map, int mx, int my, int terrain)
set terrain type for a cell (bounds-checked)
void iso_screen_to_map(const ISO_MAP *map, float screen_x, float screen_y, int *mx, int *my)
convert screen pixel coordinates to map tile coordinates (flat, no height)
void iso_map_randomize(ISO_MAP *map)
randomize terrain and height for testing/demo purposes
void iso_generate_transition_masks(ALLEGRO_BITMAP **masks, int tile_w, int tile_h)
Generate the 32 procedural transition alpha masks (16 edge + 16 corner).
void(* N_ISO_OBJECT_DRAW_FN)(float screen_x, float screen_y, float zoom, float alpha, void *user_data)
Object draw callback.
const ISO_TILE_SEGMENTS * iso_map_get_segments(const ISO_MAP *map, int mx, int my)
get per-tile segments.
int iso_map_get_height(const ISO_MAP *map, int mx, int my)
get height for a cell (bounds-checked, clamped)
float iso_map_interpolate_height(const ISO_MAP *map, float fx, float fy)
bilinear height interpolation at fractional map coordinates
void n_iso_camera_world_to_screen(const N_ISO_CAMERA *cam, float wx, float wy, float *sx, float *sy)
Convert world coordinates to screen pixel coordinates.
void iso_screen_to_map_height_f(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my, float *out_fx, float *out_fy)
height-aware screen-to-map conversion returning fractional tile coordinates.
void iso_screen_to_map_height(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my)
height-aware screen-to-map conversion with diamond hit testing.
void iso_map_corner_heights(const ISO_MAP *map, int mx, int my, float *h_n, float *h_e, float *h_s, float *h_w)
compute average corner heights for smooth rendering (Article 2026)
void n_iso_camera_scroll(N_ISO_CAMERA *cam, float dx, float dy)
Scroll the camera by (dx, dy) world units.
int free_map(MAP **map)
Free the map.
N_ISO_CAMERA * n_iso_camera_new(float zoom_min, float zoom_max)
Create a new camera with the given zoom limits.
int create_empty_map(MAP **map, const char *name, int XSIZE, int YSIZE, int TILEW, int TILEH, int nbmaxobjects, int nbmaxgroup, int nbmaxanims, int nbtiles, int nbanims)
Create an empty map.
Draw order entry for segment-sorted rendering.
Height-aware isometric map with terrain and height layers.
Axonometric projection parameters.
Single vertical segment of a tile: solid matter from bottom to top.
Per-tile height segments.
Per-tile edge visibility flags for height border rendering.
MAP with objects, tiles, skins (legacy structure)
2D isometric camera for viewport management.
Drawable object for depth-sorted isometric rendering.
Common headers and low-level functions & define.