/******************************************************************************
	enbuoy.h
******************************************************************************/

#ifndef ENBUOY_H
#define ENBUOY_H

#include "ot_sea.h"

/******************************************************************************
	define constants
******************************************************************************/

/*---------------------------------------------------------------------------*/
/* size */

#define BUOY_RADIUS	50	/* right, left */
#define BUOY_RADIUS_C	50	/* check */
#define BUOY_RADIUS_G	80	/* goal */
#define CRSBUOY_RADIUS	25
#define CHECK_GATE_WD	1600
#define GOALLINE_WD	1000
#define GOALLINE_WD_DOL	740
#define PNTBUOY_WD	256
#define THRBUOY_WD	800
#define JUMPDAI_HT1	60
#define JUMPDAI_HT2	80
#define HAKO_OBJ_WD	50
#define DRUM_OBJ_WD	25
#define ICE_OBJ_WD	50

/*---------------------------------------------------------------------------*/
/* buoy's kind */

enum {
	BUOY_KD_RIGHT = 0,
	BUOY_KD_LEFT,
	BUOY_KD_CHECK,
	BUOY_KD_GOAL,
	BUOY_KD_CENTER,
	BUOY_KD_FINISH,
	BUOY_KD_FORK,
	BUOY_KD_JOIN,
	BUOY_KD_THR,
	BUOY_KD_THR_C,
	BUOY_KD_WARP,
	BUOY_KD_ST1,
	BUOY_KD_ST2,
	BUOY_KD_ST3,
	BUOY_KD_ST4
};

/*---------------------------------------------------------------------------*/
/* buoy's user */

#define BUOY_USER_BOTH	0
#define BUOY_USER_PL	1

#define BUOY_USER_EN	2	/* EN -> EN4 must be continuous */
#define BUOY_USER_EN1	3
#define BUOY_USER_EN2	4
#define BUOY_USER_EN3	5
#define BUOY_USER_EN4	6

/*---------------------------------------------------------------------------*/
/* course buoy's kind */

#define CRSBUOY_KD_IN		0
#define CRSBUOY_KD_OUT		1
#define CRSBUOY_KD_OBSTACLE	2
#define CRSBUOY_KD_OBSTACLE2	3
#define CRSBUOY_KD_XPA		4
#define CRSBUOY_KD_FIX		5

/*---------------------------------------------------------------------------*/
/* course object's kind, fdsp, fmove, fcol */

enum {
	CRSOBJ_KD_START = 0,
	CRSOBJ_KD_JUMP,
	CRSOBJ_KD_GATE,
	CRSOBJ_KD_MIZUKUSA,
	CRSOBJ_KD_MIZUKUSA2,
	CRSOBJ_KD_HAKO,
	CRSOBJ_KD_MOKUHEN,
	CRSOBJ_KD_BOX,
	CRSOBJ_KD_RING,
	CRSOBJ_KD_DRUM,
	CRSOBJ_KD_ICE,
	CRSOBJ_KD_MAN
};

#define CRSOBJ_DSP_NONE		0
#define CRSOBJ_DSP_NORM		1
#define CRSOBJ_DSP_TURN		2
#define CRSOBJ_DSP_RING		3

#define CRSOBJ_MOVE_NONE	0
#define CRSOBJ_MOVE_VERT	1
#define CRSOBJ_MOVE_HORI	2
#define CRSOBJ_MOVE_GATE	3
#define CRSOBJ_MOVE_FLOAT	4
#define CRSOBJ_MOVE_RING	5

#define	CRSOBJ_COL_NONE		0
#define	CRSOBJ_COL_RECPIPE	1
#define	CRSOBJ_COL_SPHERE	2

/*---------------------------------------------------------------------------*/
/* fogwall */
#define FOGWALL_MAX	4

/******************************************************************************
	structures
******************************************************************************/

/*---------------------------------------------------------------------------*/
/* buoy, check, goal, finish */

typedef struct {
	float	px, py, pz;	/* dynamic pos center */
	float	lpx, lpy, lpz;	/* dynamic pos left */
	float	rpx, rpy, rpz;	/* dynamic pos right */

	float	ox, oz;		/* original pos center */
	float	lox, loz;	/* original pos left */
	float	rox, roz;	/* original pos right */

	float	vx, vy, vz;	/* velocity center */
	float	lvx, lvy, lvz;	/* velocity left */
	float	rvx, rvy, rvz;	/* velocity right */

	float	tpx, tpy, tpz;	/* top of pyramid */
	
	float	ag;		/* front vector's angle */
	float	fx, fz;		/* normalized front vector */
	
	float	sx, sz;		/* normalized side (left) vector */

	float	ax, az;		/* normalized side (aim) vector */
	
	float	ds;		/* distance to next */

	float	wd;		/* gate width */
	
	float	ends;		/* distance to next for enemy */
	float	crsang;		/* course line angle [deg] */

	int	type, tp;	/* type */
	int	c1, c2;		/* child index */
	int	pa;		/* parent index */
	int	enc1, enpa;	/* index for enemy */
	int	dtc1, dtpa;	/* index of data */

	int	fturn;		/* if turn not 0 */
	
	int	user;		/* user (player or enemy or both) */

	int	fcol;		/* collision flag */

	int	fdsp;		/* display flag */

	int	cpc1[MACHINE_KD_MAX];	/* child index for cpu */

	int	sp6;
	int	sp7;
	
	float	cx, cz;		/* normalized vector to next buoy */
	float	dx, dz;		/* normalized aim vector perpendicular to (cx, cz) */

	int	cppa[MACHINE_KD_MAX];	/* parent index for cpu */
	
} Buoy;

/*---------------------------------------------------------------------------*/
/* course buoy */

typedef struct {
	float	px, py, pz;	/* dynamic pos */
	float	rd;		/* radius */
	int	type;		/* type */
	int	ffall;		/* fall flag */
} Crsbuoy;

/*---------------------------------------------------------------------------*/
/* point buoy */

typedef struct {
	float	lpx, lpy, lpz;	/* dynamic pos left */
	float	rpx, rpy, rpz;	/* dynamic pos right */
	float	lvx, lvy, lvz;	/* velocity left */
	float	rvx, rvy, rvz;	/* velocity right */
	float	ox, oz;		/* original pos center */
	float	lox, loz;	/* original pos left */
	float	rox, roz;	/* original pos right */
	float	fx, fz;		/* normalized front vector */
	float	sx, sz;		/* normalized side (left) vector */
	int	fg;		/* if passed not 0 */
} Pntbuoy;

/*---------------------------------------------------------------------------*/
/* rectangular parallelepiped */

typedef struct {
	float	px, py, pz;	/* one point */
	float	ax, ay, az;	/* normal vector 1 */
	float	bx, by, bz;	/* normal vector 2 */
	float	cx, cy, cz;	/* normal vector 3 */
	float	al, bl, cl;	/* length of each side */
	int	fg;		/* flag (if jumpdai not 0) */
} Recpipe;

/*---------------------------------------------------------------------------*/
/* course objetct */

typedef struct {
	float	px, py, pz;	/* dynamic pos */
	float	rx, ry, rz;	/* rotation angle */
	float	vx, vy, vz;	/* velocity */
	float	ox, oy, oz;	/* original pos */
	float	fx, fz;		/* normalized front vector */
	float	sx, sz;		/* normalized side (left) vector */
	float	wd;		/* width */
	float	ht;		/* height */
	float	ag;		/* angle */
	int	kd;		/* kind */
	int	tp;		/* type */
	int	fdsp;		/* display flag */
	int	fmove;		/* move flag */
	int	fcol;		/* collision flag */
	Recpipe	*precpipe;	/* pointer to recpipe data */
	int	irecpipe;	/* index of using recpipe */
	int	nofrecpipe;	/* number of using recpipe */
	int	c1, c2;		/* counter */
	Mtxf	mf;		/* modeling matrix (float) */
	Gfx	*pgfx, *pgfxT;	/* pointer to shape data */
	int	fg;		/* if passed not 0 (ring) */
	int	no;		/* number (ring) */
} Crsobj;

/*---------------------------------------------------------------------------*/
/* wave generator */

typedef struct {
	float	px, pz;		/* pos */
	float	vx, vz;		/* unit vector (length = TRI_SIZE) */
	float	amp;		/* amplitude */
	int	frq;		/* frequency */
	int	fmove;		/* move flag */
	int	num;		/* number of unit */
	int	kd;		/* kind */
} Wavegen;

/*---------------------------------------------------------------------------*/
/* fogwall */

typedef struct {
	float	px, py, pz;	/* pos */
	int	fg;		/* appear flag */
} Fogwall;

/******************************************************************************
	external variables
******************************************************************************/
extern Buoy	buoy[BUOY_MAX], buoy2[BUOY_MAX], buoy3[BUOY_MAX];
extern int	nofbuoy, nofbuoy2, nofbuoy3;
extern int	ngoalbuoy;
extern int	nfinishbuoy;
extern int	nofscaring;

extern Crsbuoy	crsbuoy[CRSBUOY_MAX];
extern int	nofcrsbuoy;

extern Crsobj	crsobj[CRSOBJ_MAX];
extern int	nofcrsobj;

extern Wavegen	wavegen[WAVEGEN_MAX];
extern int	nofwavegen;

extern Bigwave	bigwave[BIGWAVE_MAX];
extern int	nofbigwave;

extern Recpipe	recpipe[RECPIPE_MAX];
extern int	nofrecpipe;

extern Fogwall	fogwall[FOGWALL_MAX];

extern int	idemoboat;

/******************************************************************************
	external functions
******************************************************************************/

extern void InitBuoy(int num);
extern void DoBuoy(void);
extern void DrawBuoy(Gfx **ppgfx);
extern void DrawBeam(Gfx **ppgfx);

extern void make_hover_start_matrix(int n, Mtx *mtx);

extern void InitYuki(void);
extern void DoYuki(void);
extern void DrawYuki(Gfx **ppgfx);
extern void SetYuki(float px, float py, float pz,
	float vx, float vy, float vz);

extern void InitDrawNameLetter(Gfx **ppgfx);

#endif
