#ifndef _LEVEL_H
#define _LEVEL_H

#include "WoumInclude:lib/gp/spr.h"

#define GRAVITY 0x200000

typedef struct {
	char spr_name[13]; /* Sprite name */
	gp_spr *spr; /* Sprite */
	int flags; /* Flags! */
	int i; /* Checkpoint ID etc. */
} block;

#define BLOCK_WALL 1 /* Solid wall */
#define BLOCK_HOLE 2 /* Hole to fall through */
#define BLOCK_GRID 4 /* Starting grid, 'i' is the direction */
#define BLOCK_CHECK 8 /* Checkpoint, 'i' is the number */
#define BLOCK_JUMP 16 /* Jump ramp, 'i' gives direction */
#define BLOCK_AI_HINT 32 /* AI hint, 'i' gives number */
#define BLOCK_DEFAULT 64 /* Default block for level edge & undefined cells */
#define BLOCK_HOLESPR 128 /* Is the hole sprite (implies BLOCK_HOLE) */

#define BLOCK_I_UP 1
#define BLOCK_I_DOWN 2
#define BLOCK_I_LEFT 3
#define BLOCK_I_RIGHT 4

#define MAX_BLOCK 256

typedef struct {
	int w,h; /* Level size */
	int *map; /* Map */
	block blocks[MAX_BLOCK]; /* Block definitions */
	int sprw,sprh; /* Sprite width & height */
	int highest_check; /* Highest checkpoint in level */
	int background; /* Block ID of the background sprite */
	int defaultb; /* Block ID of the default block */
	int *checkpoints; /* Array of grid/checkpoint coords, in order */
	int numhints; /* Number of AI hints (waypoints) */
	int *hints; /* Hint coords */ 
} level;

extern level *load_level(char *name);
extern void kill_level(level *l);
extern int block_find(level *l,int b,int *x,int *y); /* Find a block, returns !0 on failure. *x and *y will be filled with block coords if the pointers are provided */
extern int block_find_flag(level *l,int f,int i); /* Find a block id by flag/i pair. Returns -1 on failure. */
extern void draw_level(level *l,gp_screen *s,int x,int y); /* Draw level, with camera focused on pixel x,y */
extern int map_read(level *l,int x,int y); /* Return block type */
extern f1616 ground_height(level *l,int b,f1616 xofs,f1616 yofs); /* Return ground height at this point in this block type */

#endif
