/*-
 * Copyright (c) 2000
 * Tatsuya Kudoh(CDR/TK),ROYALPANDA.    All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */
#ifndef _SOARI_H_
#define _SOARI_H_

#include<stdlib.h>

#define NUM_ROOM_X	4
#define NUM_ROOM_Y	4

#define NUM_ENE		12

#define ROOM_WIDTH	16
#define ROOM_HEIGHT	6

#define MAP_WIDTH	(ROOM_WIDTH*NUM_ROOM_X+1)
#define MAP_HEIGHT	(ROOM_HEIGHT*NUM_ROOM_Y+1)

#define VERSION		"0.0"


typedef struct{
	unsigned *data;		/* width * height words */
	int width;		/* width in font */
	int height;		/* height in font */
	int off_x;		/* x offset from Bottom-Left (in pixels) */
	int off_y;		/* y offset from Bottom-Left (in pixels) */
}sprite_t;


typedef struct{
	unsigned char *map;
	int width;
	int height;
	int prob_floor;
}map_t;


typedef struct{
	int xx;
	int yy;

	int x;
	int y;
	int vx;
	int vy;
	int dir;
	int stat;
	int count;
	int life;
	int life_max;

	int attack;		/* max damage */
	int attack_count;	/* 0 to 256 */
	int attack_ready_speed;	/* add to attack_count when ready to attack */
	int attack_speed;	/* sub from attack_count when attacking */
	int *damage_table;	/* damage Look-up table,[0]to[255] for 1-256 */

	int damage_time;

	int jump;
	int damage;

}hero_t;

typedef struct ene_t_ {
	struct ene_t_ *next;

	int xx;
	int yy;

	int x;
	int y;
	int vx;
	int vy;
	int dir;
	int count;
	int stat;
	int value[8];
	int graphic;
	int life;
	int life_max;
	int attack;
	int damage;

	int score;

	void (*func)( struct ene_t_ *ep, hero_t *hp );
}ene_t;



#define rnd(n)		(rand() % (n))
#define abs(n)		((n) < 0 ? -(n) : (n))


void init_disp( void );
void draw_map( int x, int y, int ex, int ey, map_t *mp );
void show_level( int level );
void show_score( unsigned score );
unsigned clear_level( hero_t *hp, unsigned score, int life_bonus, int level_bonus );
int regist_sprite( sprite_t *p, int x, int y, unsigned palette );
void clear_sprite( void );
void init_scroll( map_t *mp, int x, int y );
void scroll( map_t *mp, int x, int y );
void refresh_screen( void );
void draw_hero( hero_t *hp );
void draw_ene( ene_t *ep );
void draw_letter( char far *str, int x, int y );
void draw_life_hero( hero_t *hp );
void draw_attack( hero_t *hp );
void draw_life_ene( ene_t *ep );
void erase_life_ene( void );
unsigned game( int *lv,map_t *mp, hero_t *hp, ene_t *ene, int num_ene );
void create_map( map_t *map, int width, int height, int prob_loop );
void fade_out( void );
void fade_in( void );
void layout_ene( int width, int height, ene_t *ene_list, int hx, int hy );
void wait_v( void );
void set_fontdata_game( void );
int title( int mode, unsigned score, unsigned hiscore, int level );
void draw_title( void );
void draw_label( void );
void draw_gameover( void );
void draw_pause( int pause );
#endif
