/*** sot_ai.h ***/

#define ABS(x) ((x) >= 0 ? (x) : -(x))
//#define BUOYCONV(type) ( (type) == BUOY_KD_RIGHT ? -1 : (type) == BUOY_KD_LEFT ? 1 : type)

#define LEFT 1
#define RIGHT -1
#define NO_HIT 0
#define HIT 1    
/*** マシンの名前 ***/
#define HAYAMI 0
#define MARINER 1
#define STEWART 2
#define JETER 3
/*** こけかた ***/
#define NO_CLASH 0
#define FREE_CLASH 1		/* 吹き飛んでいる状態 */
#define FREEBOARD_CLASH 2	/* 吹き飛んでから上がろうとしている */
#define FREE_RECOVER 3		/* ボートの方向を戻している状態 */
    
/*** STRUCTURE ***/
typedef struct{
    float px0,pz0;
    float px1,pz1;
    float fx,fz;
//    float vx,vz;
    float f;
} Vector;

typedef struct{
    int p_distance; /* 通過時のブイとボートの距離 */
    int check; /* 無事通過したか */
    int b_distance; /* 前のブイとの距離 */
    int h_distance; /* ブイとの距離がいくらでハンドルを切り始めるか */
} Buoy_pass;

typedef struct{
    int number; /* ボートの番号 */
    int rnumber; /* 人間の種類 */

    int ienbnext,ienbtype;
    int target,child,parent; /* 目指すブイ,その子,親 */
    int targettype,childtype,parenttype;

    int buoy_angle; /* ブイの角度（カーブのきつさ） */

    int line_distance; /* 自機とブイの通過判定ラインとの距離 */
    int line_target_distance;
    int buoy_distance; /* 目標のブイとその親ブイの距離 */
    int ienb_distance; /* 目標のブイとボートの距離 */

    int line_direction; /* ブイのどちら側にいるか */
    int reverse_flag;

    int turn_distance; /* ブイとの距離がいくらでハンドルを切り始めるか */

    float sea_high, sea_high_front; /* 海の高さ */
    float sea_high_left, sea_high_right;
    int sea_contact_counter;
    
    int ai_grid; /* どのくらい敵が手を抜くか */    
    float accel_mult;
    
    float handle_max;
    float handle_cos;
    
    int control_mode;    

    int crsbuoy_flag;
    int crs6_flag;
    int crs6_light_flag; /* ブイに照らされているか */

    int action_count;
    int action_flag[3];

    int clash_flag; /* こけているか、こけかたの種類 */
    int stop_count;

    int hit_flag; /* 壁などの障害物に当っているか */
    int near_jumpbox; /* じゃんぷだい に ちかいか */
    int boxjump; /* じゃんぷだい をつかって じゃんぷ ちゅう */
    int beach_count; /* すなはま に いる ふれーむ すう */

    int camera_flag; /* かめらに うつる はんい に いるか */

    int stick_x_back; /* はんどる の さゆう の ばっくあっぷ */

    int chace_counter; /* ぷれいや に まけてて かめら に うつってない ときの かうんた */
    int chace_flag;
    int wave_hit_flag; /* なみ の えいきょう を うけるか */
    
    float fx,fy, fz, fxback,fyback, fzback;
    float fx_2D, fz_2D;

    int wall_count; /* かべにちかい きけんちたい に いる じかん */
    int wall_flag;

    int updown_flag;
    int dummy;
} Status;

/*** FUNCTIONS ***/
extern void auto_control_one(int number);
extern void culc_infomation(void);
extern void culc_vector(void);
extern void vector_normalize_2D(float *vx, float *vz);
extern Gfx *draw_aim(Gfx *gp);
extern void set_ai_data(void);
extern int get_dir(float px,float pz, float x1, float z1, float x2, float z2);
extern float get_line_distance(float px,float pz,float x1,float z1,float x2,float z2);
extern void getVector(Vector *vector);
/***** VARIABLES *****/
extern Boat *one;
extern Buoy *buoy_ptr;
extern Status *rstatus;
extern Status status_data[BOAT_MAX];
extern Vector vector0,vector1,vector2,vector3,vector4,vector5,vector6,vector7;
extern int ai_rank[BOAT_MAX];
extern int tour_setting[8+1][4][3];
extern int nofjump;
extern int jump_index[];
