/*＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊*/
/*＊	スターフォックス６４					＊*/
/*＊	ＶＳゲームに関すること		96年11月 4日（月曜日）	＊*/
/*＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊*/
/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	ｉｎｃｌｕｄｅ宣言					┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
#include "sys_main.h"
#include "sys_fault.h"
#include "fox_std_types.h"
#include "fox_std_lib.h"
#include "fox_vs_poly.h"
#include "fox_main.h"
#include "fox_ram.h"
#include "fox_play.h"
#include "fox_enmy.h"
#include "fox_enmy2.h"
#include "fox_title.h"
#include "fox_beam.h"
#include "fox_bg.h"
#include "fox_texture.h"
#include "fox_moji.h"
#include "fox_std_rcp.h"
#include "fox_data.h"
#include "fox_exst.h"
#include "../audio/audio_game.h"
#include "fox_eeprom.h"
#include "fox_fade.h"
#include "fox_std_Dmoji.h"

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	プロトタイプ宣言					┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
	int	vs_game_observer( void );	/* ＶＳ仕様（制御る〜ちん）	*/
	void	vs_display( void );		/* ＶＳ仕様（表示る〜ちん）	*/
	void	Game_Reset( void );		/* ゲームリセット		*/

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	ｅｘｔｅｒｎ宣言					┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
extern	void	vs_status_reset( void );	/* ＶＳゲームリセット		*/
extern	int	Win_Count[ 4];			/* それぞれの勝ち星		*/
extern	int	Win_No[ 4][ 10];		/* だれを倒した			*/
extern	float	p4_p;				/* 画面セットようのカウンタ	*/
extern	int	PlayerMode[ 4];			/* プレイヤーモード		*/
extern	int	VS_start;			/* ＶＳゲーム開始フラグ		*/
extern	int	VsReturn;			/* ？？？？？			*/
extern	int	title_return;			/* ？？？？？			*/
extern	int	pl_lock[ 4][ 4];		/* ホーミングロック情報		*/
extern	u16	vs_hit_count[ 4];		/* ＶＳヒット数			*/
extern	int	Win_Flag;			/* 勝者発生フラグ		*/

extern	void	number_disp( float, float, float, int );
extern	void	wolf_damage_check( ENMS * );
extern	void	seisan_suuji_disp( float, float, int, float, int, int );
extern	int	before_mode;

/* ゲーム用コントローラポインター */
extern	OSContPad   *Pad;
extern	OSContPad   *Pad_T;

//extern	int	wolf_yama_check( ENMS * );

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	グローバル変数						┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
	int	vs_end_flg;			/* ＶＳおわりフラグ		*/
	int	vs_phase;			/* 仕様フェイズ			*/
        int     vs_time;                        
	int	vs_t_flag;			/* 戦車出撃フラグ		*/
	int	vs_h_flag;			/* 人間出撃フラグ		*/
	int	clock_time[ 4];			/* タイムトライアル用タイマ	*/

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	ローカル変数						┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
static	int	vs_display_phase;		/* 仕様（表示る〜ちん）フェイズ	*/
static	int	select[ 4];			/* マシンセレクト済みフラグ	*/
static	int	vs_cnt;				/* カウントダウン		*/
static	int	count_timer;			/* カウントダウンタイマー	*/
static	int	wtimer;				/* ウェイトタイマー		*/
static	int	keyin_count;			/* キー入力用カウンタ		*/
static	int	keyin_timer;			/* キー入力用タイマー		*/
static	int	sel_no;				/* 選択メニュー			*/
static	int	winner;				/* 勝利者			*/
static	float	flash_0_col;			/* 文字点滅用ワーク		*/
static	float	flash_1_col;			/* 文字点滅用ワーク		*/
static	int	menber;				/* 参加人数			*/
static	int	wincnt;				/* 勝ち星表示用カウント		*/

static	int	win_msge_phase;			/* 勝ちメッセージの移動フェイズ	*/
static	float	win_msge_add_x;			/* 勝ちメッセージの移動量	*/
static	float	win_msge_speed;			/* 勝ちメッセージの移動スピード	*/
static	float	win_msge_scl;			/* 勝ちメッセージのスケール	*/
static	float	window_0_scl;			/* 上メニューのウィンドスケール	*/
static	float	window_1_scl;			/* 下メニューのウィンドスケール	*/

static	float	flash_col_w[ 4];		/* 「カメラ」の表示カラー	*/
static	float	flash_col_m[ 4];		/* 「カメラ」の目標カラー	*/
static	int	sel_time[ 4];			/* マシンセレクト待ち時間	*/
static	u16	vs_old_score[ 4];		/* タイムトライアルの得点（表示用）	*/
static	int	vs_score_tim[ 4];		/* 得点アニメ用カウンタ	*/
static	int	vs_crash_cnt[ 4];		/* 墜落した回数		*/
static	int	wipe_cont;			/* ワイプカウント	*/
static	int	TB_score_wk[ 5];		/* タイムバトルの清算用ワーク	*/
static	int	TB_phase = 0;			/* タイムバトル清算処理のシーケンス	*/
static	int	TB_total = 0;			/* タイムバトルの合計得点	*/
static	int	vs_frcnt = 0;			/* */
static	int	reach_flag = 0;			/* リーチかかった？	*/
static	int	reach_sound= 0;			/* リーチサウンドふらぐ	*/
static	int	retry_disp_f[ 4];		/* "カメラ"・ましん選択メニュー表示フラグ	*/
static	OSTime	vs_m_sec;			/* 時間対比用	*/
static	OSTime	vs_m_cmp;			/* 時間対比用	*/

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【共通さぶる〜ちん集】					┃*/
/*┃								┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	ゲームリセット						  */
/******************************************************************/
void	Game_Reset( void )
{
    register int	i;
    
    mem_stage_clear();
    object_clear();

    for(i = 0; i < play_mode; i++) {
	Na_StopObjectSe( Pl[ i].sound_ps );
	Na_StopPlayerEngine( i );
    }
    
    system_mode		= SYSTEM_INIT;
    system_time		= 2;
    play_mode		= P_SINGLE;
    game_mode		= 0; 
    display_mode	= 0;
    title_mode 		= 0; 
    option_mode		= 0; 
    map_mode		= 0; 
    BG_color		= 0;
    sun_A[0]		= 0; 
    sun_A[1]		= 0; 
    sun_A[2]		= 0; 
    sun_A[3]		= 0; 
    Dma_No		= 0;
    face_stat		= 0;
    VS_flag		= 0;
    fade_A_f		= 0;
    fade_A		= 255;
    
    First_start = 1;	/* 最初だけ通る */
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【描画る〜ちん集】						┃*/
/*┃								┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	決定（→ＷＡＩＴに変更  97.03.14）			  */
/******************************************************************/
static	void	VTX_AC_display( float xp, float yp, float scl )
{
#if LOCALE==CHINA
    texture_rectangleIA8( &NOW_DISP, VTX_Z_WEIT_txt, 64, 17, xp, yp, scl, scl );
#else
    texture_rectangleIA8( &NOW_DISP, VTX_WEIT_txt, 64, 17, xp, yp, scl, scl );
#endif
}

/******************************************************************/
/*	ＲＥＡＤＹ						  */
/******************************************************************/
static	void	VTX_READY_display( float xp, float yp, float scl )
{
    register int	i;

#if LOCALE==CHINA
    for(i=0;i<2;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_Z_READY_txt+(152*8*i), VS_Z_READY_txttlut,
			      152, 8,
			      xp, yp+(float)(8*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_Z_READY_txt+(152*8*i), VS_Z_READY_txttlut,
			  152, 7,
			  xp, yp+(float)(8*i*scl), scl, scl );
#else
    for(i=0;i<2;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_READY_txt+(152*8*i), VS_READY_txttlut,
			      152, 8,
			      xp, yp+(float)(8*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_READY_txt+(152*8*i), VS_READY_txttlut,
			  152, 7,
			  xp, yp+(float)(8*i*scl), scl, scl );
#endif
}

/******************************************************************/
/*	カウントダウンの数字（１〜３）				  */
/******************************************************************/
static	void	VTX_R1_display( float xp, float yp, float scl, int no )
{
    unsigned short	*txttlut[]	= { VS_R1_txttlut, VS_R2_txttlut,
					    VS_R3_txttlut, };
    unsigned char 	*txt[]		= { VS_R1_txt, VS_R2_txt,
					    VS_R3_txt, };
    int			size_x[]	= { 40, 64, 64, };
    register int	i;
    
    for(i=0;i<5;i++) {
	texture_rectangleCI8( &NOW_DISP, txt[ no]+(size_x[ no]*8*i), txttlut[ no],
			      size_x[ no], 8, xp, yp+(8*i*scl), scl, scl );
    }
}

/******************************************************************/
/*	ＧＯ！！						  */
/******************************************************************/
static	void	VTX_GO_display( float xp, float yp, float scl )
{
    register int	i;

#if LOCALE==CHINA
    for(i=0;i<2;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_Z_GO_txt+(96*8*i), VS_Z_GO_txttlut,
			      96, 8, xp, yp+(8*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_Z_GO_txt+(96*8*i), VS_Z_GO_txttlut,
			  96, 7, xp, yp+(8*i*scl), scl, scl );
#else
    for(i=0;i<2;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_GO_txt+(96*8*i), VS_GO_txttlut,
			      96, 8, xp, yp+(8*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_GO_txt+(96*8*i), VS_GO_txttlut,
			  96, 7, xp, yp+(8*i*scl), scl, scl );
#endif
}

/******************************************************************/
/*	ＦＯＸ・ＦＡＬＣＯ・ＳＬＩＰＰＹ・ＰＥＰＰＹ		  */
/******************************************************************/
static	void	VTX_FOX_display( float xp, float yp, float x_scl, float y_scl, int no )
{
#if LOCALE==CHINA
    unsigned short	*txttlut[]	= { VS_Z_FOX_txttlut, VS_Z_PEPPY_txttlut,
					    VS_Z_SLIPPY_txttlut, VS_Z_FALCO_txttlut, };
    unsigned char	*txt[]		= { VS_Z_FOX_txt, VS_Z_PEPPY_txt,
					    VS_Z_SLIPPY_txt, VS_Z_FALCO_txt, };
#else
    unsigned short	*txttlut[]	= { VS_FOX_txttlut, VS_PEPPY_txttlut,
					    VS_SLIPPY_txttlut, VS_FALCO_txttlut, };
    unsigned char	*txt[]		= { VS_FOX_txt, VS_PEPPY_txt,
					    VS_SLIPPY_txt, VS_FALCO_txt, };
#endif
    int			size_x[]	= { 104, 152, 168, 152, };
    register int	i;

    for(i=0;i<3;i++) {
	texture_rectangleCI8( &NOW_DISP, txt[ no]+(size_x[ no]*8*i), txttlut[ no],
			      size_x[ no], 8,
			      xp, yp+(float)(8*i*y_scl), x_scl, y_scl );
    }
    texture_rectangleCI8( &NOW_DISP, txt[ no]+(size_x[ no]*8*i), txttlut[ no],
			  size_x[ no], 1,
			  xp, yp+(float)(8*i*y_scl), x_scl, y_scl );
}

/******************************************************************/
/*	ＤＲＡＷ						  */
/******************************************************************/
static	void	VS_DRAW_display( float xp, float yp, float x_scl, float y_scl )
{
    register int	i;

#if LOCALE==CHINA
    for( i=0; i<6; i++ ) {
	texture_rectangleCI8( &NOW_DISP, VS_Z_DRAW_txt+(256*7*i), VS_Z_DRAW_txttlut, 256, 7, xp, yp+(float)(7*i*y_scl), x_scl, y_scl );
    }
#else
    for( i=0; i<6; i++ ) {
	texture_rectangleCI8( &NOW_DISP, VS_DRAW_txt+(256*7*i), VS_DRAW_txttlut, 256, 7, xp, yp+(float)(7*i*y_scl), x_scl, y_scl );
    }
#endif
}

/******************************************************************/
/*	ＷＩＮ！						  */
/******************************************************************/
static	void	VTX_WIN_display( float xp, float yp, float scl )
{
    register int	i;

#if LOCALE==CHINA
    for(i=0;i<12;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_Z65_txt+(136*2*i), VS_Z65_txttlut,
			      136, 2,
			      xp, yp+(float)(2*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_Z65_txt+(136*2*i), VS_Z65_txttlut,
			  136, 1,
			  xp, yp+(float)(2*i*scl), scl, scl );
#else
    for(i=0;i<12;i++) {
	texture_rectangleCI8( &NOW_DISP, VS_E65_txt+(136*2*i), VS_E65_txttlut,
			      136, 2,
			      xp, yp+(float)(2*i*scl), scl, scl );
    }
    texture_rectangleCI8( &NOW_DISP, VS_E65_txt+(136*2*i), VS_E65_txttlut,
			  136, 1,
			  xp, yp+(float)(2*i*scl), scl, scl );
#endif
}

/******************************************************************/
/*	メッセージのウィンド					  */
/******************************************************************/
static	void	JT_mess_display( float xp, float yp, float xscl, float yscl )
{
    texture_rectangleCI8( &NOW_DISP, JT_mess_txt, JT_mess_txttlut, 24, 17,
 			  xp, yp, xscl, yscl );
}

/******************************************************************/
/*	リトライ						  */
/******************************************************************/
static	void	VTX_mess44_display( float xp, float yp, float scl )
{
#if LOCALE==CHINA
    texture_rectangleCI4( &NOW_DISP, VS_Z63_txt, VS_Z63_txttlut,
			  64, 12, xp, yp-2, scl, scl );
#else
    texture_rectangleCI4( &NOW_DISP, VS_E63_txt, VS_E63_txttlut,
			  64, 10, xp, yp, scl, scl );
#endif
}

/******************************************************************/
/*	ＶＳメニュー						  */
/******************************************************************/
static	void	VTX_mess44b_display( float xp, float yp, float scl )
{
#if LOCALE==CHINA
    texture_rectangleCI4( &NOW_DISP, VS_Z64_txt, VS_Z64_txttlut,
			  80, 12, xp, yp-1, scl, scl );
#else
    texture_rectangleCI4( &NOW_DISP, VS_E64_txt, VS_E64_txttlut,
			  80, 10, xp, yp, scl, scl );
#endif
}

/******************************************************************/
/*	ＥＮＤ							  */
/******************************************************************/
static	void	VTX_mess44c_display( float xp, float yp, float scl )
{
#if LOCALE==CHINA
    texture_rectangleCI4( &NOW_DISP, VS_Z66_txt, VS_Z66_txttlut,
			  64, 12, xp, yp, scl, scl );
#else
    texture_rectangleCI4( &NOW_DISP, VS_E66_txt, VS_E66_txttlut,
			  64, 10, xp, yp, scl, scl );
#endif
}

/******************************************************************/
/*	マシンセレクト・アーウィン				  */
/******************************************************************/
static	void	VTX_m01_display( float xp, float yp )
{
    texture_rectangleIA8( &NOW_DISP, VTX_a_icon_txt, 16, 16, xp, yp, 1.0f, 1.0f );
}

/******************************************************************/
/*	マシンセレクト・タンク					  */
/******************************************************************/
static	void	VTX_m02_display( float xp, float yp )
{
    texture_rectangleIA8( &NOW_DISP, VTX_t_icon_txt, 16, 16, xp, yp, 1.0f, 1.0f );
}

/******************************************************************/
/*	マシンセレクト・人間					  */
/******************************************************************/
static	void	VTX_m03a_display( float xp, float yp )
{
    texture_rectangleIA8( &NOW_DISP, VTX_f_icon_txt, 16, 16, xp, yp, 1.0f, 1.0f );
}

/******************************************************************/
/*	Ａボタン・アイコン					  */
/******************************************************************/
static	void	VTX_A_display( float xp, float yp )
{
    texture_rectangleCI8( &NOW_DISP, VTX_Abotan_txt, VTX_Abotan_txttlut,
			  16, 16, xp, yp, 1.0f, 1.0f );
}

/******************************************************************/
/*	Ｂボタン・アイコン					  */
/******************************************************************/
static	void	VTX_B_display( float xp, float yp )
{
    texture_rectangleCI8( &NOW_DISP, VTX_Bbotan_txt, VTX_Bbotan_txttlut,
			  16, 16, xp, yp, 1.0f, 1.0f );
}
/******************************************************************/
/*	Ｃボタン・アイコン					  */
/******************************************************************/
static	void	VTX_C_display( float xp, float yp )
{
    texture_rectangleCI8( &NOW_DISP, VTX_Cbotan_txt, VTX_Cbotan_txttlut,
			  16, 16, xp, yp, 1.0f, 1.0f );
}
/******************************************************************/
/*	マシンセレクト・ボタンをおして‥‥			  */
/******************************************************************/
static	void	VTX_osite_display( float xp, float yp )
{
#if LOCALE==CHINA
    texture_rectangleCI8( &NOW_DISP, VTX_Z100_txt, VTX_Z100_txttlut,
			  64, 19, xp, yp, 1.0f, 1.0f );
#else
    texture_rectangleCI8( &NOW_DISP, VTX_E100_txt, VTX_E100_txttlut,
			  64, 19, xp, yp, 1.0f, 1.0f );
#endif
}

/******************************************************************/
/*	マシンセレクト・選択のカコミ				  */
/******************************************************************/
static	void	VTX_player_waku_display( float xp, float yp )
{
    register int	i;
    for( i=0; i<8; i++ ) {
	texture_rectangleCI4( &NOW_DISP, VTX_player_waku_txt+((80*8*i)/2), VTX_player_waku_txttlut,
			      80,  8, xp, yp+(i*8), 1.0f, 1.0f );
    }
    texture_rectangleCI4( &NOW_DISP, VTX_player_waku_txt+((80*8*i)/2), VTX_player_waku_txttlut,
			  80,  7, xp, yp+(i*8), 1.0f, 1.0f );
}

/******************************************************************/
/*	マシンセレクト・選択の制限時間				  */
/******************************************************************/
static	void	select_time_display( float x, float y, int n )
{
    unsigned char	*txt[] = 	{
	MOJI_00_txt, MOJI_01_txt, MOJI_02_txt, MOJI_03_txt, MOJI_04_txt, 
	MOJI_05_txt, MOJI_06_txt, MOJI_07_txt, MOJI_08_txt, MOJI_09_txt
    };
    int			flg, i, j;

    flg= OFF;
    i = 1000;
    n %= i;

    for( i/=10; i!=1; i/=10 ) {
	j= n/ i;
	if( j || flg==ON ) {
	    texture_rectangleIA8( &NOW_DISP, txt[ j/i], 16, 8, x, y, 1.0f, 1.0f );
	    x += 9.0f; 
	    n %= i;
	    flg=ON;
	}
    }
    texture_rectangleIA8( &NOW_DISP, txt[ n/i], 16, 8, x, y, 1.0f, 1.0f );
}

/******************************************************************/
/*	勝ち星							  */
/******************************************************************/
static	void	VS_win_display( float xp, float yp )
{
    texture_rectangleIA8( &NOW_DISP, VS_win_txt, 8, 8, xp, yp, 1.0f, 1.0f );
}

/******************************************************************/
/*	カメラ							  */
/******************************************************************/
static	void	VTX_mess65_display( float xp, float yp )
{
#if LOCALE==CHINA
    texture_rectangleCI4( &NOW_DISP, VS_Z60_txt, VS_Z60_txttlut,
			  64, 13, xp, yp, 1.0f, 1.0f );
#else
    texture_rectangleCI4( &NOW_DISP, VS_E60_txt, VS_E60_txttlut,
			  64, 13, xp, yp, 1.0f, 1.0f );
#endif
}
#if 0
/******************************************************************/
/*	ダメ・メッセージ					  */
/******************************************************************/
static	void	VTX_dame_display( float xp, float yp )
{
    register int	i;

    for(i=0;i<18;i++) {
	texture_rectangleIA8( &NOW_DISP, VS_dame_txt+((192*2*i)/2),
			      192, 2, xp, yp+(i*2), 1.0f, 1.0f );
    }
}
#endif
/******************************************************************/
/*	数字							  */
/******************************************************************/
static	void	MOJI_00_display( float x, float y, int num )
{
    unsigned char	*txt[] = 	{
	MOJI_00_txt, MOJI_01_txt, MOJI_02_txt, MOJI_03_txt, MOJI_04_txt, 
	MOJI_05_txt, MOJI_06_txt, MOJI_07_txt, MOJI_08_txt, MOJI_09_txt
    };
    register int	i;

    for(i=10;i!=1;i/=10) {
	if( x > 0 && y > 0 ) {
	    texture_rectangleIA8( &NOW_DISP, txt[num/i],
				  16, 8, x, y, 1.0f, 1.0f );
	}
	x+=9.0f;
	num%=i;
    }
    if( x > 0 && y > 0 ) {
	texture_rectangleIA8( &NOW_DISP, txt[num/i],
			      16, 8, x, y, 1.0f, 1.0f );
    }
}

/******************************************************************/
/*	：							  */
/******************************************************************/
static	void	JT_tenten_display( float x, float y )
{
    texture_rectangleCI4( &NOW_DISP, JT_tenten_txt, JT_tenten_txttlut,
			  16, 8, x, y, 1.0f, 1.0f );
}

/******************************************************************/
/*	ロックされてるよマーク					  */
/******************************************************************/
static	void	LOCK_display( float x, float y )
{
    texture_rectangleIA8( &NOW_DISP, MOJI_l_txt, 8, 8, x, y, 1.0f, 1.0f );
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【タイムトライアル特別処理（その１）】			┃*/
/*┃	撃墜した敵の数を表示する				┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	得点描画						  */
/******************************************************************/
static	void	vs_score_sub( float x, float y, int new, int old, int cont )
{
    unsigned char	*txt[] = 	{
	MOJI_s0_txt, MOJI_s1_txt, MOJI_s2_txt, MOJI_s3_txt, MOJI_s4_txt,
	MOJI_s5_txt, MOJI_s6_txt, MOJI_s7_txt, MOJI_s8_txt, MOJI_s9_txt,
    };
    register int	i;
    int			nw, ow, nbak, obak;
    
    i = 1000;
    nbak = new;
    obak = old;
    new %= i;
    old %= i;
    for( i/=10; i>=1; i/=10 ) {
	nw = new/ i;
	ow = old/ i;
	if( nw==ow ) {
	    texture_rectangleIA8( &NOW_DISP, txt[ nw], 16, 15, x, y, 0.7f, 0.7f );
	}
	else {
	    if( nbak> obak ) {
		texture_rectangleIA8( &NOW_DISP, txt[ ow]+(16*cont), 16, 15-cont, x, y, 0.7f, 0.7f );
		texture_rectangleIA8( &NOW_DISP, txt[ nw], 16,    cont, x, y+( (float)( 15-cont )*0.7f ), 0.7f, 0.7f );
	    }
	    if( nbak< obak ) {
		texture_rectangleIA8( &NOW_DISP, txt[ ow], 16, 15-cont, x, y+( (float)( cont*0.7f ) ), 0.7f, 0.7f );
		texture_rectangleIA8( &NOW_DISP, txt[ nw]+(16*(15-cont)), 16, cont, x, y, 0.7f, 0.7f );
	    }
	}
	x += (13.0f*0.7f);
	new %= i;
	old %= i;
    }
}

/******************************************************************/
/*	撃墜数：制御る〜ちん					  */
/******************************************************************/
static	void	vs_score_ctrl( void )
{
}

/******************************************************************/
/*	撃墜数：表示る〜ちん					  */
/******************************************************************/
static	void	vs_score_disp( void )
{
    register int	i;
    float	x[] = {  82.0f, 242.0f,  82.0f, 242.0f, };
    float	y[] = {  82.0f,  82.0f, 202.0f, 202.0f, };
    
    rcpsetmode( &NOW_DISP, RECT_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255,   0, 255 );
    for( i=0; i<4; i++ ) {
	if( ( Pl[ i].mode==PMOVE )||( Pl[ i].mode==PTURN ) ) {
	    if( ( vs_hit_count[ i]!=vs_old_score[ i] )||( vs_score_tim[ i] ) ) {
		if( ( vs_score_tim[ i]+= 4 )> 15 ) {
		    if( vs_hit_count[ i]> vs_old_score[ i] )	vs_old_score[ i]+= 1;
		    else					vs_old_score[ i]-= 1;
		    if( vs_hit_count[ i]!=vs_old_score[ i] )	vs_score_tim[ i]-=15;
		    else					vs_score_tim[ i] = 0;
		    Na_StartSystemSe( NA_SE_COUNT_UP );
		}
	    }
	    if( vs_hit_count[ i]>= vs_old_score[ i] )
		vs_score_sub( x[ i], y[ i], vs_old_score[ i]+ 1, vs_old_score[ i], vs_score_tim[ i] );
	    else
		vs_score_sub( x[ i], y[ i], vs_old_score[ i]- 1, vs_old_score[ i], vs_score_tim[ i] );
	}
    }
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【タイムトライアル特別処理（その２）】			┃*/
/*┃	制限時間を表示する					┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	タイムトライアル用タイマー：制御る〜ちん		  */
/******************************************************************/
static	int	clock_ctrl( void )
{
    int		atai;
    
    for(;;) {
	atai = 	(int)OS_CYCLES_TO_USEC( ( vs_m_sec- vs_m_cmp ) ) / 10000;
	
	if( ( clock_time[ 2]-=atai )>= 0 )	break;
	clock_time[ 2] *=  -1;
	atai = ( clock_time[ 2]/ 100 )+ 1;
	clock_time[ 2] %= 100;
	clock_time[ 2]= ( 100- clock_time[ 2] )% 100;
	
	if( ( clock_time[ 1]-=atai )>= 0 ) {
	    if( clock_time[ 0]==0 && clock_time[ 1]< 15 && clock_time[ 1]>= 0 ) {
		Na_StartSystemSe( NA_SE_COUNTDOWN );	/* それ以外	*/
	    }
	    break;
	}
	if( clock_time[ 0]==0 )	Na_StartSystemSe( NA_SE_TIME_OVER );	/* ０の場合	*/

	clock_time[ 1] *= -1;
	atai = ( clock_time[ 1]/ 60 )+ 1;
	clock_time[ 1] %= 60;
	clock_time[ 1]= ( 60- clock_time[ 1] )% 60;
	
	if( ( clock_time[ 0]-=atai )>= 0 )	break;
	clock_time[ 0] = 0;
	clock_time[ 1] = 0;
	clock_time[ 2] = 0;
	break;
    }
    return( 0 );
}

/******************************************************************/
/*	タイムトライアル用タイマー：表示る〜ちん		  */
/******************************************************************/
static	int	clock_disp( float x, float y, int *time )
{
    register int	i;
    float		px, xx, yy;
    int			tm;

    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0,   0,   0,   0, 255 );
    texture_rectangleCI8( &NOW_DISP, JT_mess_txt, JT_mess_txttlut, 24, 17,
			  120.0f, 115.0f, 3.33f, 0.53f );
    px = 0.0f;
    xx = x;
    yy = y;
    for( i=0; i<5; i++ ) {
	if( (i==0)||(i==2) )	tm = time[i/2]% 60;
	if( i==4 )		tm = time[i/2]%100;
	if( ( i%2 )==1 ) {
	    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	    JT_tenten_display( xx+px, yy );
	}
	else {
	    rcpsetmode( &NOW_DISP, RECT_A_PRIM );
	    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255,   0, 255 );
	    MOJI_00_display( xx+px, yy, tm );
	    px += 9.0f;
	}
	px += 9.0f;
    }
    return( 0 );
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【ＶＳ仕様・その３】					┃*/
/*┃	マシンセレクトからゲーム開始までの処理。		┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	マシンセレクト：制御る〜ちん				  */
/******************************************************************/
static	int	machine_select_ctrl( void )
{
    register int	i;
    int			ret = 0;

    if( ( vs_t_flag==0 && vs_h_flag==0 )||	/* 戦車or人間が使える？	*/
	( VS_stage==2 ) ) {			/* ステージは宇宙？	*/
	for( i=0; i<4; i++ ) {
	    if( PlayerMode[ i] )	continue;
	    select[ i] =1;
	    VS_stat[ i]=WING;
	    ret += 1;
	}
	return( ret );
    }

    for(i=0;i<4;i++) {
	if( PlayerMode[ i] )	continue;
	if( ( !select[ i] )&&( sel_time[ i]==0 ) ) {	/* 時間切れ？	*/
	    if( ( vs_t_flag!=0 )&&( vs_h_flag!=0 ) )	select[ i]= (int)( rnd()* 3.0f )+ 1;
	    if( ( vs_t_flag!=0 )&&( vs_h_flag==0 ) )	select[ i]= (int)( rnd()* 2.0f )+ 1;
	}
	if( sel_time[ i] )	sel_time[ i]-= 1;
	if( ( vs_t_flag )&&( select[ i]==0 )&&( Key_T[ i].button & CONT_B ) ) {
	    Na_StartSystemSe( NA_SE_DECIDE );
	    select[ i]= 2;
	}
 	if( ( vs_h_flag )&&( select[ i]==0 )&&
	    ( ( Key_T[ i].button & CONT_C )||
	      ( Key_T[ i].button & CONT_D )||
	      ( Key_T[ i].button & CONT_E )||
	      ( Key_T[ i].button & CONT_F ) )
	) {
 	    Na_StartSystemSe( NA_SE_DECIDE );
 	    select[ i]= 3;
 	}
 	if( ( select[ i]==0 )&&( Key_T[ i].button & CONT_A ) ) {
 	    Na_StartSystemSe( NA_SE_DECIDE );
	    select[ i]= 1;
	}
	if( select[ i] ) {
	    switch( select[ i] ) {
	    case	1:	VS_stat[ i]= WING;	break;
	    case	2:	VS_stat[ i]= TANK;	break;
	    case	3:	VS_stat[ i]= HUMAN;	break;
	    default:	VS_stat[ i]= WING;	break;
	    }
	    ret += 1;
	}
    }
    return( ret );
}

/******************************************************************/
/*	マシンセレクト：マシン決定前の表示			  */
/******************************************************************/
static	void	select_menu_display( int no )
{
    float	x[] = {  40.0f, 200.0f,  40.0f, 200.0f, };
    float	y[] = {  20.0f,  20.0f, 140.0f, 140.0f, };
    
    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
    VTX_player_waku_display( x[ no]+ 0.0f, y[ no]+10.0f );
    VTX_osite_display( x[ no]+ 5.0f, y[ no]+ 0.0f );

    if( ( vs_t_flag!=0 )&&( vs_h_flag!=0 ) ) {	/* すべて選択できる	*/
	rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
	VTX_A_display( x[no]+15.0f, y[no]+22.0f );
	VTX_B_display( x[no]+15.0f, y[no]+40.0f );
	VTX_C_display( x[no]+15.0f, y[no]+58.0f );
	
	rcpsetmode( &NOW_DISP, RECT_A_PRIM );
	VTX_m01_display ( x[no]+43.0f, y[no]+22.0f );
	VTX_m02_display ( x[no]+43.0f, y[no]+40.0f );
	VTX_m03a_display( x[no]+43.0f, y[no]+58.0f );
    }
    
    if( ( vs_t_flag!=0 )&&( vs_h_flag==0 ) ) {	/* 戦車を選択できる	*/
	rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
	VTX_A_display( x[no]+15.0f, y[no]+29.0f );
	VTX_B_display( x[no]+15.0f, y[no]+51.0f );
	
	rcpsetmode( &NOW_DISP, RECT_A_PRIM );
	VTX_m01_display ( x[no]+43.0f, y[no]+29.0f );
	VTX_m02_display ( x[no]+43.0f, y[no]+51.0f );
    }
    
    rcpsetmode( &NOW_DISP, RECT_A_PRIM );	/* 制限時間	*/
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255,   0, 255 );
    select_time_display( x[ no]+32.0f, y[ no]+84.0f, ( sel_time[ no]/30 )+ 1 );
}

/******************************************************************/
/*	マシンセレクト：マシン決定後の表示			  */
/******************************************************************/
static	void	accept_display( int no )
{
    float		x[]	= {  40.0f, 200.0f,  40.0f, 200.0f, };
    float		y[]	= {  40.0f,  40.0f, 160.0f, 160.0f, };

    rcpsetmode( &NOW_DISP, RECTANGLE_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255,  30,   0, 255 );
    VTX_AC_display( x[ no], y[ no], 1.0f );
}

/******************************************************************/
/*	マシンセレクト：ＲＥＡＤＹの表示			  */
/******************************************************************/
static	int	ready_msg_display( void )
{
    rcpsetmode( &NOW_DISP, RECTANGLE_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
    VTX_READY_display( 84.0f, 108.0f, 1.0f );
}

/******************************************************************/
/*	マシンセレクト：表示る〜ちん				  */
/******************************************************************/
static	int	machine_select_disp( void )
{
    register int	i;
    int			cnt = 0;

    if( ( vs_t_flag==0 && vs_h_flag==0 )||	/* 戦車or人間が使える？	*/
	( VS_stage==2 ) 			/* ステージが宇宙？	*/
    ) {
	ready_msg_display();
	return( 0 );
    }

    for(i=0;i<4;i++) {	/* ポイントマッチなら	*/
	if( PlayerMode[ i] )	continue;
	if( !select[ i] )	select_menu_display( i );
	else			accept_display( i );
	if( select[ i] )	if(menber==(cnt+=1))	ready_msg_display();
    }
    return( 0 );
}

/******************************************************************/
/*	カウントダウン：制御る〜ちん				  */
/******************************************************************/
static	int	count_down_ctrl( void )
{
    int		ret = 0;

    if( !vs_cnt )	return( 2 );
    if( !( --count_timer ) ) {
	if( (--vs_cnt) ) {
	    Na_StartSystemSe( NA_SE_READY );
	}
	else {
	    Na_StartSystemSe( NA_SE_GO );
	    ret = 1;
	}
	count_timer = 30;
    }	return( ret );
}

/******************************************************************/
/*	カウントダウン：表示る〜ちん				  */
/******************************************************************/
static	int	count_down_disp( void )
{
    float		x[]	= {  46.0f, 206.0f,  46.0f, 206.0f, };
    float		y[]	= {  40.0f,  40.0f, 160.0f, 160.0f, };
    float		add_x[]	= {  12.0f,   0.0f,   0.0f, };
    register int	i;

    rcpsetmode( &NOW_DISP, RECTANGLE_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
    for(i=0;i<4;i++) {
	if( PlayerMode[ i] )	continue;
	if( vs_cnt )	VTX_R1_display( x[ i]+add_x[vs_cnt-1], y[ i], 1.0f, vs_cnt-1 );
	else		VTX_GO_display( x[ i]-16.0f, y[ i], 1.0f );
    }
    return( 0 );
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【ＶＳリトライ待ち】					┃*/
/*┃	ＶＳゲームで負けたプレイヤーの再戦待ち処理。		┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	ＶＳリトライ待ち：制御る〜ちん				  */
/******************************************************************/
static	int	vs_retry_wait_ctrl( void )
{
    register int	i;
    float		ret;

    for(i=0,ret=0;i<4;i++){

	retry_disp_f[ i]= 1;
	if( Pl[ i].mode!=PCAMERA ) {
	    retry_disp_f[ i]= 0;
	    sel_time[ i]= 5* 30;
	    continue;
	}
	if( ( PlayerMode[ i] )||( VS_game_mode==1 )||
	    ( ( menber==1 )&&( VS_game_mode!=2 ) )||
	    ( ( VS_game_mode==2 )&&( clock_time[ 0]==0 )&&( clock_time[ 1]==0 )&&( clock_time[ 2]==0 ) )
	) {	/* カメラ		 */
	    ret = add_calc( &flash_col_w[ i], flash_col_m[ i], 0.3f, 100.0f, 1.0f );
	    if( ret==0.0f ) {
		if( flash_col_m[ i]==32.0f )	flash_col_m[ i]=255.0f;
		else				flash_col_m[ i]= 32.0f;
	    }
	    Pl[ i].wrk0 = 0;	/* 戦線復帰しない	*/
	}
	else {			/* マシンセレクト	*/
	    select[ i] = 0;
	    Pl[ i].wrk0= 0;
	    if( ( !select[ i] )&&( sel_time[ i]==0 ) ) {	/* 時間切れ？	*/
		if( ( vs_t_flag!=0 )&&( vs_h_flag!=0 ) )	select[ i]= (int)( rnd()* 3.0f )+ 1;
		if( ( vs_t_flag!=0 )&&( vs_h_flag==0 ) )	select[ i]= (int)( rnd()* 2.0f )+ 1;
	    }
	    if( sel_time[ i] )	sel_time[ i]-= 1;
	    if( ( vs_t_flag!=0 )&&( select[ i]==0 )&&( Key_T[ i].button & CONT_B ) ) {
//		Na_StartSystemSe( NA_SE_DECIDE );
		select[ i]= 2;
	    }
	    if( ( vs_h_flag!=0 )&&( select[ i]==0 )&&
		( ( Key_T[ i].button & CONT_C )||
		  ( Key_T[ i].button & CONT_D )||
		  ( Key_T[ i].button & CONT_E )||
		  ( Key_T[ i].button & CONT_F ) )
	    ) {
//		Na_StartSystemSe( NA_SE_DECIDE );
		select[ i]= 3;
	    }
	    if( ( select[ i]==0 )&&( Key_T[ i].button & CONT_A ) ) {
//		Na_StartSystemSe( NA_SE_DECIDE );
		select[ i]= 1;
	    }
	    if( ( ( vs_t_flag==0 )&&( vs_h_flag==0 ) )||( VS_stage==2 ) ) {	/* 強制的にアーウィンの場合	*/
		retry_disp_f[ i]= 0;
		select[ i]= 1;
	    }
	    if( select[ i]!=0 ) {
		switch( select[ i] ) {
		case	1:	VS_stat[ i]= WING;	break;
		case	2:	VS_stat[ i]= TANK;	break;
		case	3:	VS_stat[ i]= HUMAN;	break;
		default:	VS_stat[ i]= WING;	break;
		}
		vs_crash_cnt[ i]+= 1;	/* 復活した回数	*/
//		vs_status_reset();	/* プレイヤーせっと	*/

		if( VS_game_mode==2 ) {	/* 得点関連すべてクリア	*/
		    vs_hit_count[ i]= TB_score_wk[ i]= vs_old_score[ i]= vs_score_tim[ i]= 0;
		}
		Pl[ i].wrk0 = 1;	/* 戦線復帰	*/
//		Key_T[ i].button = Key_T[ i].button | CONT_A;	/* めっちゃ強引。押したことにする	*/
	    }
	}
    }
    return( 0 );
}

/******************************************************************/
/*	ＶＳリトライ待ち：表示る〜ちん				  */
/******************************************************************/
static	int	vs_retry_wait_disp( void )
{
    register int	i;
    float		x[] = {  83.0f, 226.0f,  83.0f, 226.0f, };
    float		y[] = { 102.0f, 102.0f, 209.0f, 209.0f, };
    int			col;
    
    for(i=0;i<4;i++) {

	rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	if( retry_disp_f[ i]==0 )	continue;
	if( ( PlayerMode[ i] )||( VS_game_mode==1 ) ) {	/* カメラ	*/
	    col = (int)flash_col_w[ i];
	    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, col, col, 255 );
	    VTX_mess65_display( x[ i], y[ i] );
	}
	else {			/* マシンセレクト	*/
	    if( ( vs_t_flag!=0 )||( vs_h_flag!=0 ) )	select_menu_display( i );
	}
    }
    return( 0 );
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【ＶＳ仕様・その５】					┃*/
/*┃	勝ちメッセージからメニュー選択まで処理。		┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	ロックされたマークの表示				  */
/******************************************************************/
static	void	warning_disp( void )
{
    register int	i, j;
    float	x[]= { 112.0f, 272.0f, 112.0f, 272.0f, };
    float	y[]= {  75.0f,  75.0f, 195.0f, 195.0f, };
    int		r[]= { 177, 255,   0,  30, }; 
    int		g[]= { 242,  30, 179,  30, }; 
    int		b[]= {  12,   0,  67, 255, }; 
    int		cont;

    rcpsetmode( &NOW_DISP, RECT_A_PRIM );
    for( i=0; i<4; i++ ) {
	if( Pl[ i].mode!=PMOVE )	continue;
	for( j=0, cont=0; j<4; j++ ) {
	    if( ( pl_lock[ i][ j]!=0 )&&( frcnt&4 ) ) {
		gDPSetPrimColor( NEXT_DISP, 0, 0, r[ j], g[ j], b[ j], 255 );
		LOCK_display( x[ i]+cont*9.0f, y[ i] );
		cont += 1;
	    }
	}
    }
}

/******************************************************************/
/*	勝ち確定？						  */
/******************************************************************/
static	int	end_vs_game_check( void )
{
    register int	i,j;
    int			onaji, cnt, ranking[ 4];

    switch( VS_game_mode ) {
	
    case	0:	/* ポイントマッチ	*/

	for(i=0, cnt=0;i<4;i++) {
	    if( Pl[ i].mode!=PCAMERA )	winner= i;
	    if( Pl[ i].mode==PCAMERA )	cnt+= 1;
	}
	if( ( menber==1 )&&( cnt==4 ) ) {	/* 一人でやってて死んだときは必ずＤＲＡＷ	*/
	    Win_Flag = ON;
	    winner = 99;
	    break;
	}

	for(i=0;i<4;i++) {
	    if( Win_Count[ i]==VS_point )	break;
	    if( Win_Count[ i]==VS_point-1 ) {
		reach_flag= 1;	/* リーチかかった	*/
	    }
	}
	if( i>=4 )			return( 0 );
	if( Pl[ i].win_count_set )	return( 0 );
	
	for(j=0;j<4;j++) {	/* 勝者に注目	*/
	    if( j==i )	continue;
	    if( Pl[ j].fail_OP >= 0 )	Pl[ j].fail_OP = i+1;
	    Pl[ j].mode = PCAMERA;
	}
	Win_Flag = ON;
	winner	= i;
	break;

    case	1:	/* バトルロイヤル	*/

	for(i=0, cnt=0;i<4;i++) {
	    if( Pl[ i].mode!=PCAMERA )	winner= i;
	    if( Pl[ i].mode==PCAMERA )	cnt+= 1;
	}
	if( ( menber==1 )&&( cnt==4 ) ) {	/* 一人でやってて死んだときは必ずＤＲＡＷ	*/
	    Win_Flag = ON;
	    winner = 99;
	    break;
	}
	if( cnt >= 2 )	reach_flag= 1;	/* リーチかかった	*/

	if( ( cnt< 3 )||( menber==1 ) )		return( 0 );
	if( cnt>=4 )		winner = 99;	/* 勝者なし（ＤＲＡＷ）	*/

	for(j=0;j<4;j++) {	/* 勝者に注目	*/
	    if( j==winner )	continue;
	    if( Pl[ j].fail_OP >= 0 )	Pl[ j].fail_OP = i+1;
	    Pl[ j].mode = PCAMERA;
	}
	Win_Flag = ON;
	break;

    case	2:	/* タイムトライアル	*/

			/* 時間切れ？	*/
	if( ( clock_time[ 0]!=0 )||
	    ( clock_time[ 1]!=0 )||
	    ( clock_time[ 2]!=0 ) ) {
	    return( 0 );
	}

	if( VS_game_mode==2 ) {	/* 墜落中またはカメラになっているやつは得点クリア	*/
	    for( i=0; i<4; i++ ) {
		if( Pl[ i].mode==PFAIL || Pl[ i].mode==PCAMERA ) {
		    vs_hit_count[ i]= TB_score_wk[ i]= vs_old_score[ i]= vs_score_tim[ i]= 0;
		    vs_crash_cnt[ i]+= 1;	/* 復活した回数	*/
		}
	    }
	}
	
#if 0
	PRINTF( "SC= %d, %d, %d, %d\n", vs_hit_count[ 0], vs_hit_count[ 1], vs_hit_count[ 2], vs_hit_count[ 3] );
	PRINTF( "CR= %d, %d, %d, %d\n", vs_crash_cnt[ 0], vs_crash_cnt[ 1], vs_crash_cnt[ 2], vs_crash_cnt[ 3] );
	PRINTF( "HP= %d, %d, %d, %d\n", Pl[ 0].shield, Pl[ 1].shield, Pl[ 2].shield, Pl[ 3].shield );
#endif
	/****	最初に、最高得点をたたき出したやつが勝者	****/
	for( i=0; i<4; i++ )	ranking[ i]= 0;	/* rankingに値が入ってるとすでに負け決定	*/
	for( i=0; i<4; i++ ) {
	    if( Key_switch[ i]==OFF )	continue;
	    for( j=0, onaji=0; j<4; j++ ) {
		if( Key_switch[ j]==OFF )	continue;	/* 不参加のやつは数えない	*/
		if( ranking[ j] )		continue;
		if( i!=j ) {
		    if( vs_hit_count[ i]< vs_hit_count[ j] ) {
			ranking[ i]= 1;
			break;
		    }
		    if( vs_hit_count[ i]==vs_hit_count[ j] )	onaji= 1;
		}
	    }
	    if( ( j==4 )&&( onaji==0 ) )	winner = i;
	}
	
	/****	この時点で、勝者が決まっていない場合	****/
	if( winner==99 ) {	/* やられた回数で判断	*/
	    for( i=0; i<4; i++ ) {
		if( Key_switch[ i]==OFF )	continue;
		if( ranking[ i] )	continue;
		for( j=0, onaji= 0; j<4; j++ ) {
		    if( Key_switch[ j]==OFF )	continue;
		    if( ranking[ j] )	continue;
		    if( i!=j ) {
			if( vs_crash_cnt[ i]> vs_crash_cnt[ j] ) {
			    ranking[ i]= 1;
			    break;
			}
			if( vs_crash_cnt[ i]==vs_crash_cnt[ j] )	onaji= 1;
		    }
		}
		if( ( j==4 )&&( onaji==0 ) )	winner = i;
	    }

	    if( winner==99 ) {	/* 残ったライフで判断	*/
		for( i=0; i<4; i++ ) {
		    if( Key_switch[ i]==OFF )	continue;
		    if( ranking[ i] )	continue;
		    for( j=0, onaji= 0; j<4; j++ ) {
			if( Key_switch[ j]==OFF )	continue;
			if( ranking[ j] )	continue;
			if( i!=j ) {
			    if( Pl[ i].shield< Pl[ j].shield ) {
				ranking[ i]= 1;
				break;
			    }
			    if( Pl[ i].shield==Pl[ j].shield )	onaji= 1;
			}
		    }
		    if( ( j==4 )&&( onaji==0 ) )	winner = i;
		}
	    }
	}

	for( j=0; j<4; j++ ) {	/* 勝者に注目	*/
	    if( j==winner )	continue;
	    if( Pl[ j].fail_OP >= 0 )	Pl[ j].fail_OP = i+1;
	    Pl[ j].mode = PCAMERA;
	}
	Win_Flag = ON;
#if 0
	PRINTF( "winner= %d\n", winner );
	PRINTF( "hit[ 0]= %d, hit[ 1]= %d, hit[ 2]= %d, hit[ 3]= %d\n",
		vs_hit_count[ 0],
		vs_hit_count[ 1],
		vs_hit_count[ 2],
		vs_hit_count[ 3]
	);
	PRINTF( "cra[ 0]= %d, cra[ 1]= %d, cra[ 2]= %d, cra[ 3]= %d\n",
		vs_crash_cnt[ 0],
		vs_crash_cnt[ 1],
		vs_crash_cnt[ 2],
		vs_crash_cnt[ 3]
	);
	PRINTF( "sld[ 0]= %d, sld[ 1]= %d, sld[ 2]= %d, sld[ 3]= %d\n",
		Pl[ 0].shield,
		Pl[ 1].shield,
		Pl[ 2].shield,
		Pl[ 3].shield
	);
	PRINTF( "\n" );
#endif	
	break;

    default:
	break;
	
    }
    return( 1 );
}

/******************************************************************/
/*	勝ったやつの名前：イニシャライズ			  */
/******************************************************************/
static	void	winner_name_init( void )
{
    win_msge_phase	=   1;
    wtimer		=   0;
    win_msge_speed	=   0.0f;
    win_msge_scl	=   1.0f;
    win_msge_add_x	= 400.0f;
}

/******************************************************************/
/*	勝ったやつの名前：制御る〜ちん				  */
/******************************************************************/
static	int	winner_name_ctrl( int no )
{
//    float	x[]	= { 120.0f,  90.0f,  76.0f,  94.0f,  36.0f, };
    float	x[]	= { 108.0f,  84.0f,  79.0f,  84.0f,  36.0f, };
    int		ret = 0, cnt;

    if( no==99 )	no= 4;
    switch( win_msge_phase ) {

    case	0:	/* */
	break;

    case	1:	/* 左からきて	*/
	if( (win_msge_add_x-=(win_msge_speed+=10.0f)) <= x[ no]*0.8f ) {
	    win_msge_phase = 2;
	    win_msge_add_x = x[ no]*0.8f;
	}
	break;

    case	2:	/* 縮んで	*/
	if( 0.0f==add_calc( &win_msge_scl, 0.3f, 0.4f, 100.0f, 0.01f ) ) {
	    win_msge_phase = 3;
	    win_msge_speed = 0.0f;
	}
	break;

    case	3:	/* 定位置に	*/
	cnt = add_calc( &win_msge_scl, 1.0f, 0.6f, 100.0f, 0.1f );
	if( win_msge_add_x < x[ no] )	win_msge_add_x += (win_msge_speed+=3.0f);
	else			win_msge_add_x  = x[ no];
	if( ( win_msge_add_x == x[ no] )&&( cnt==0.0f ) )	win_msge_phase = 4;
	break;

    default:		/* おしまい	*/
	ret = 1;
	break;
    }
    return( ret );
}

/******************************************************************/
/*	勝ったやつの名前：表示る〜ちん				  */
/******************************************************************/
static	int	winner_name_disp( float xp, float scl, int no )
{
    float	xx, yy;
    
    if( ( VS_game_mode==2 )&&( vs_frcnt&32 )&&( winner!=99 ) ) {	/* トータルスコア	*/

	xx = 118.0f;	/* 基準ポジション	*/
	yy = 110.0f;
	
		/* メッセージウィンド	*/ 
	rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	gDPSetPrimColor( NEXT_DISP, 0, 0,   0,   0,   0, 200 );
	JT_mess_display(  98.0f, 100.0f, 5.2f, 2.98f );

		/* 文字	*/
	rcpsetmode( &NOW_DISP, RECE_A_PRIM );
	gDPSetPrimColor( NEXT_DISP, 0, 0,  255, 255,   0, 255 );
#if LOCALE==CHINA
	small_moji_puts( 140, yy, 1.0f, 1.0f, "TOTAL SCORE" );
#else
	small_moji_puts( xx, yy, 1.0f, 1.0f, "TOTAL" );
	small_moji_puts( xx+ 45.0f, yy, 1.0f, 1.0f, "SCORE" );
#endif

		/* 得点	*/
	gDPSetPrimColor( NEXT_DISP, 0, 0,  255, 255, 255, 255 );
	seisan_suuji_disp( xx+ 18.0f, yy+ 16.0f, TB_total, 1.0f, 0, 9999 );
    }
    else {	/* 勝者の名前	*/
	if( no < 4 ) {
	    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
	    VTX_FOX_display( xp, 100.0f, scl, 1.0f, no );
	}
	else {
	    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
	    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
	    VS_DRAW_display( xp, 104.0f, scl, 1.0f );
	}
    }
    return( 0 );
}

/******************************************************************/
/*	勝ちメッセージ：表示る〜ちん				  */
/******************************************************************/
static	int	win_message_disp( void )
{
    rcpsetmode( &NOW_DISP, RECT_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
    VTX_WIN_display( 106.0f- 12.0f, 126.0f, 1.0f );
    return( 0 );
}

/******************************************************************/
/*	メニュー選択：キー入力（縦方向のみ）			  */
/******************************************************************/
static	int	keyin_move_cur( void )
{
    register int	i;
    int		keyin	= 0;
    int		ret	= 0;

    for( i=0; i<4; i++ ) {
	if( Key_switch[ i]==ON ) {
	    if( keyin=Key_T[ i].stick_y )	break;
	}
    }
    if( keyin ) {
	if( keyin > 0 )	keyin = -1;
	else		keyin =  1;
	if( !keyin_count )	ret = keyin;
	keyin_timer++;
	keyin_count = keyin;
    }
    else {
	keyin_count = 0;
	keyin_timer = 0;
    }
    if( ret )	Na_StartSystemSe( NA_SE_CURSOR );
    return( ret );
}

/******************************************************************/
/*	ウィンドオープン：制御る〜ちん				  */
/******************************************************************/
static	int	menu_window_ctrl( void )
{
    float	fwork = 0.0f;
    
    fwork += add_calc( &window_0_scl, 1.55f, 0.6f, 10.0f, 0.04f );
    fwork += add_calc( &window_1_scl, 0.82f, 0.6f, 10.0f, 0.04f );
    if( fwork!=0.0f )	return( 0 );
    else		return( 1 );
}

/******************************************************************/
/*	ウィンドオープン：表示る〜ちん				  */
/******************************************************************/
static	int	menu_window_disp( float scl_0, float scl_1 )
{
    rcpsetmode( &NOW_DISP, RECTANGLE_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0,   0,   0,   0, 255 );
#if LOCALE==CHINA
    JT_mess_display(  98.0f,  71.0f, 5.19f, scl_0+.1 );
    JT_mess_display(  98.0f, 152.0f, 5.19f, scl_1+.1 );
#else
    JT_mess_display(  98.0f,  72.0f, 5.19f, scl_0 );
    JT_mess_display(  98.0f, 152.0f, 5.19f, scl_1 );
#endif
}

/******************************************************************/
/*	メニュー選択：制御る〜ちん				  */
/******************************************************************/
static	int	select_menu_ctrl( void )
{
    float	ret;
    int		add;

    if( add=keyin_move_cur() ) {
	flash_0_col = 255.0f;
	flash_1_col = 255.0f;
	sel_no += add;
	if( sel_no > 2 )	sel_no = 0;
	if( sel_no < 0 )	sel_no = 2;
    }
    ret = add_calc( &flash_0_col, flash_1_col, 0.5f, 100.0f, 1.0f );

    if( ret==0.0f ) {
	if( flash_1_col==32.0f )	flash_1_col = 255.0f;
	else				flash_1_col =  32.0f;
    }
    return( sel_no );
}

/******************************************************************/
/*	メニュー選択：表示る〜ちん				  */
/******************************************************************/
static	int	select_menu_disp( void )
{
    register int	i;
    int			rgb[ 3];
    
    rcpsetmode( &NOW_DISP, RECTANGLE_RGBA_A_PRIM );
    for(i=0;i<3;i++) {
	if( i==sel_no )	rgb[ i] = (int)flash_0_col;
	else		rgb[ i] = 255;
    }
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, rgb[ 0], rgb[ 0], 255 );
    VTX_mess44_display (  140.0f,  74.0f, 1.0f );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, rgb[ 1], rgb[ 1], 255 );
    VTX_mess44b_display(  124.0f,  86.0f, 1.0f );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, rgb[ 2], rgb[ 2], 255 );
    VTX_mess44c_display(  144.0f, 154.0f, 1.0f );
    return( 0 );
}

/******************************************************************/
/*	メニュー選択						  */
/******************************************************************/
static	int	select_menu( void )
{
    register int	i;

    for( i=0; i<4; i++ ) {
	if( Key_switch[ i]==ON ) {
	    if( Key_T[ i].button & CONT_A ) {
		flash_0_col = 32.0f;
		return( 1 );
	    }
	}
    }
    select_menu_ctrl();
    return( 0 );
}

/******************************************************************/
/*	タイムバトル結果：制御る〜ちん				  */
/******************************************************************/
static	int	TB_result_ctrl( void )
{
    register int	i;
    int			cont, ret = 0;

    switch( TB_phase ) {

    case	0:	/* イニシャル	*/
	for( i=0; i<5; i++ )	TB_score_wk[ i]= 0;
	TB_phase = 1;
	TB_total = 0;
	break;

    case	1:	/* 得点清算中	*/
	cont = 0;
	for( i=0; i<4; i++ ) {
	    if( vs_hit_count[ i]==TB_score_wk[ i] ) {
		cont+= 1;
		continue;
	    }
	    TB_score_wk[ i]+= 1;
	    TB_total+= 1;
	}
	if( cont==4 )	TB_phase= 2;
	else		Na_StartSystemSe( NA_SE_COUNT_UP );
	break;

    case	2:	/* 合計点計算中	*/
	if( TB_score_wk[ 4]!=TB_total )	TB_score_wk[ 4]+= 1;
	else				ret = 1;
	break;

    default:
	break;
    }
    return( ret );
}

/******************************************************************/
/*	タイムバトル結果：表示る〜ちん				  */
/******************************************************************/
static	int	TB_result_disp( void )
{
    register int	i;
    unsigned char	*txt[]= {
                                  "FOX ",
				  "PEPPY",
				  "SLIPPY",
				  "FALCO",
    };
    float	mo_xps[ 5] = {  32.0f, 168.0f,  32.0f, 168.0f, 0.0f, };
    float	mo_yps[ 5] = {  20.0f,  20.0f, 200.0f, 200.0f, 0.0f, };

    for( i=0; i<4; i++ ) {
	if( Key_switch[ i]==ON ) {	
			/* 文字	*/
	    rcpsetmode( &NOW_DISP, RECE_A_PRIM );
	    gDPSetPrimColor( NEXT_DISP, 0, 0,  255, 255,   0, 255 );
	    small_moji_puts( mo_xps[ i], mo_yps[ i], 1.0f, 1.0f, txt[ i] );

	    		/* 得点 */
	    gDPSetPrimColor( NEXT_DISP, 0, 0,  255, 255, 255, 255 );
	    seisan_suuji_disp( mo_xps[ i], mo_yps[ i]+ 9.0f, TB_score_wk[ i], 1.0f, 0, 999 );
	}
    }
    return( 0 );
}

/******************************************************************/
/*	勝ち星：制御る〜ちん					  */
/******************************************************************/
static	int	vs_star_ctrl( int no )
{
    if( 10==(wtimer+=1) ) {
	Na_StartSystemSe( NA_SE_COUNT_UP );
	wincnt+=1;
	wtimer= 0;
    }
    if( wincnt < Win_Count[ no] )	return( 0 );
    return( 1 );
}

/******************************************************************/
/*	勝ち星：表示る〜ちん					  */
/******************************************************************/
static	int	vs_star_disp( int max, int no )
{
    float	x[]	= {  24.0f, 248.0f,  24.0f, 248.0f, };
    float	y[]	= { 104.0f, 104.0f, 216.0f, 216.0f, };
    int		R[]	= { 177, 255,   0,  30, };
    int		G[]	= { 242,  30, 179,  30, };
    int		B[]	= {  12,   0,  67, 255, };
    register int	i,j;

    for(i=0;i<max;i++) {
	rcpsetmode( &NOW_DISP, RECTANGLE_A_BLEND_RGBA );
	j = Win_No[ no][ i];
	gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
	gDPSetEnvColor( NEXT_DISP, R[ j], G[ j], B[ j],  0 );
	VS_win_display( x[ no]+((float)i*9.0f), y[ no] );
    }
    return( 0 );
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃【ＶＳ仕様メイン】						┃*/
/*┃	ＶＳゲームの勝敗を監視する処理。			┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
/******************************************************************/
/*	ＶＳ仕様メイン：イニシャライズ				  */
/******************************************************************/
static	void	vs_inital( void )
{
    register int	i;

//    for(i=0,menber=0;i<4;i++) {
    /* テスト	*/
#if 0
    for( i=0; i<4; i++ ) {
	PlayerMode[ i]= 0;
    }
#endif
    for( i=0, menber=0; i<4; i++ ) {
	if( !PlayerMode[ i] )	menber += 1;
	select[ i] = 0;
	flash_col_w[ i] = 0.0f;
	flash_col_m[ i] = 0.0f;
    }
    window_0_scl	=   0.0f;
    window_1_scl	=   0.0f;
    flash_0_col		= 255.0f;
    flash_1_col		=   0.0f;
    p4_p		=   0.5f;
    vs_display_phase	=   0;
    vs_cnt		=   4;
    count_timer		=   1;	/* つじつま合わせ	*/
    keyin_count		=   0;
    keyin_timer		=   0;
    sel_no		=   0;
    winner		=  99;
    wincnt		=   0;
    vs_end_flg		=   0;
    BG_color		=   0;
    wipe_cont		=   0;
    TB_phase		=   0;
    vs_frcnt		=   0;
    reach_flag= reach_sound=0;
    fade_A = 255;
    fade_A_ad= 0;
    fade_A_f = 0;

    for( i=0; i<4; i++ ) {	/* 得点表示関係クリア	*/
	vs_hit_count[ i]= 0;
	vs_old_score[ i]= 0;
	vs_score_tim[ i]= 0;
	vs_crash_cnt[ i]= 0;
    }

    /****	情報の受け取り		****/
    			/* 時間データ	*/
    for( i=0; i<4; i++ )	sel_time[ i]= 5* 30;

    			/* 戦車使える？	*/ 
    if( fox_save.rom[ 0].data.pl_stat[ 15].clear==1 )		vs_t_flag = 1;
    else							vs_t_flag = 0;
    			/* 人間使える？	*/	
    if( fox_save.rom[ 0].data.pl_stat[ 15].extra_clear==1 )	vs_h_flag = 1;
    else							vs_h_flag = 0;

    if( VS_game_mode==2 )	VS_point= 10000;	
    if( vs_t_flag==0 )	vs_h_flag= 0;
	
	/* タイムトライアル時間	*/ 
    clock_time[ 0]= VS_battle_time+ 1;	/* 分	*/
    clock_time[ 1]= 0;			/* 秒	*/
    clock_time[ 2]= 0;			/* ミリ秒	*/
}

/******************************************************************/
/*	ＶＳ仕様メイン：画面セット				  */
/******************************************************************/
static	int	vs_screen_set( void )
{
    int		ret = 0;

    if( p4_p >= 1.5f ) {
	p4_p  = 1.5f;
	switch( VS_stage ) {
	case	0:	BG_color= 0x8fbd;	break;	/* ＣＮ	*/
	case	1:	BG_color= 0xada7;	break;	/* ＫＴ	*/
	case	2:	BG_color= 0x0001;	break;	/* 宇宙	*/
	default:	BG_color= 0x8fbd;	break;	/* その他	*/
	}
	ret = 1;
    }
    else {
	p4_p += 0.05f;
	BG_color =  0;
    }
    return( ret );
}

/******************************************************************/
/*	ＶＳ仕様メイン：時間まちイニシャル			  */
/******************************************************************/
static	int	wait_timer_init( void )
{
    wtimer = 0;
}

/******************************************************************/
/*	ＶＳ仕様メイン：時間まち				  */
/******************************************************************/
static	int	wait_timer( int time )
{
    if( wtimer!=time )	wtimer += 1;
    else		return( 1 );
    return( 0 );
}

/******************************************************************/
/*	ＶＳ仕様メイン：リトライ				  */
/******************************************************************/
static	void	vs_retry( void )
{
    vs_status_reset();
    vs_phase		= 0;
    vs_display_phase	= 0;
}

/******************************************************************/
/*	ＶＳ仕様メイン：ＶＳメニューに戻る			  */
/******************************************************************/
static	void	vs_menu( void )
{
    Game_Reset();
    system_mode		= OPTION;
    system_time		= 2;
    option_mode		= OPTION_WAIT;
    VsReturn		= 1;
    BG_color		= 0;
}

/******************************************************************/
/*	ＶＳ仕様メイン：コントローラ接続チェック		  */
/******************************************************************/
static	int	vs_controller_check( void )
{
    register int	i;
    int			ret = 0;

    for(i=0;i<MAXCONTROLLERS;i++) {
	if( Key_switch[ i]==ON )	ret += 1;
    }
    return( ret );
}

/******************************************************************/
/*	コントローラ警告画面：制御る〜ちん			  */
/******************************************************************/
static	void	vs_controller_warning_ctrl( void )
{
}

/******************************************************************/
/*	コントローラ警告画面：表示る〜ちん			  */
/******************************************************************/
static	void	vs_controller_warning_disp( void )
{
#if 0    
    rcpsetmode( &NOW_DISP, RECTANGLE_RGBA_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0,   0,   0, 255, 128 );
    JT_mess_display( 52.0f, 94.0f, 9.0f, 3.0f );

    rcpsetmode( &NOW_DISP, RECTANGLE_A_PRIM );
    gDPSetPrimColor( NEXT_DISP, 0, 0, 255, 255, 255, 255 );
    VTX_dame_display( 64.0f, 102.0f );
#endif
}

/******************************************************************/
/*	ＶＳ仕様メイン：ＶＳ監視				  */
/******************************************************************/
static	int	vs_observ( void )
{
    int		ret = 0;

#if 0    
    PRINTF( "********** ささき **********\n" );
    PRINTF( "WING= %d, TANK= %d, HUMAN= %d\n", WING, TANK, HUMAN );
    PRINTF( "VS_stat[ 0]= %d\n", VS_stat[ 0] ); 
    PRINTF( "VS_stat[ 1]= %d\n", VS_stat[ 1] ); 
    PRINTF( "VS_stat[ 2]= %d\n", VS_stat[ 2] ); 
    PRINTF( "VS_stat[ 3]= %d\n", VS_stat[ 3] );
#endif    
    
    switch( vs_phase ) {

    case	 0:	/* イニシャル		*/
	vs_inital();
	vs_phase= 1;
	wait_timer_init();
	break;

    case	 1:	/* 画面セット		*/
	if( !vs_screen_set() )		break;
	if( wait_timer( 30 ) ) {
//	    if( vs_controller_check() >= 2 )	vs_phase =  2;
//	    else				vs_phase = 20;
	    Na_StartBgm( BGM_NO );
	    vs_phase = 2;
	    wait_timer_init();
	}
	break;

    case	 2:	/* マシンセレクト	*/
	vs_display_phase = 1;
	if( menber!=machine_select_ctrl() )	break;
	if( wait_timer( 30 ) ) {
	    vs_status_reset();	/* プレイヤーせっと	*/
	    vs_phase = 3;
	    wait_timer_init();
	}
	break;

    case	 3:	/* カウントダウン	*/
	vs_display_phase = 2;
	ret = count_down_ctrl();
	if( ret==0 )			break;
	if( ret==1 )			VS_start = 1;
	if( wait_timer( 30 ) ) {
	    vs_phase = 4;
	}
	break;

    case	 4:	/* ゲーム中		*/

	if( ( reach_flag==1 )&&( reach_sound==0 ) ) {	/* リーチ音楽スタート！！	*/
	    Na_StartBgm( NA_BGM_BATTLE_LAST );
	    reach_sound= 1;
	}
	
	if( VS_game_mode==2 ) {	/* タイムトライアル？	*/
	    vs_display_phase = 10;
	    clock_ctrl();
	    vs_score_ctrl();
	}
	else {
	    vs_display_phase = 8;
	}
	
	if( end_vs_game_check() ) {
	    Na_StopBgm( 1 );
	    if( VS_game_mode==2 )	vs_display_phase = 11;
	    else			vs_display_phase = 0;
	    vs_phase = 5;
	    wait_timer_init();
	}
	else {
	    vs_retry_wait_ctrl();
	}
	break;

    case	 5:	/* ＷＡＩＴ		*/
	if( wait_timer( 60 ) ) {

	    switch( winner ) {	/* ファンファーレ	*/

	    case	 0:	/* 勝者決定	*/
	    case	 1:
	    case	 2:
	    case	 3:
		Na_StartBgm( NA_BGM_COURCE_CLEAR );
		break;

	    case	99:	/* ＤＲＡＷ	*/
		Na_StartBgm( NA_BGM_COURCE_FAILURE );
		break;

	    default:
		break;

	    }
	    vs_end_flg = 1;
	    vs_phase = 6;
	    winner_name_init();
	}
	break;

    case	 6:	/* 勝ったやつの名前	*/
	vs_display_phase = 3;
	if( !winner_name_ctrl( winner ) )	break;
	if( wait_timer( 30 ) ) {
	    wait_timer_init();
	    vs_phase = 7;
	}
	break;

    case	 7:	/* 勝ちメッセージ	*/
	vs_display_phase = 4;
	if( wait_timer( 15 ) ) {
	    wait_timer_init();

	    if( ( ( VS_game_mode==0 )&&( menber> 1 ) )||	/* ポイントマッチで参加人数が二人以上か、	*/
		( VS_game_mode==2 ) ) {				/* タイムバトルなら				*/
		vs_phase= 8;					/* 結果表示シーケンスへ	*/
	    }
	    else {
		vs_phase= 9;					/* ＥＮＤメニュー表示	*/
	    }
	}
	break;

    case	 8:	/* 勝ち星		*/
	vs_display_phase = 5;
	switch( VS_game_mode ) {

	case	0:	/* ポイントマッチ	*/
	    if( vs_star_ctrl( winner ) )	vs_phase = 9;
	    break;

	case	2:	/* タイムバトル	*/
	    if( TB_result_ctrl() )		vs_phase = 9;
	    break;

	default:	/* その他	*/
	    break;
	}
	break;

    case	 9:	/* ウィンドオープン	*/
	vs_display_phase = 6;
	if( menu_window_ctrl() ) {
	    wait_timer_init();
	    flash_0_col = 0.0f;
	    wipe_cont= 0;
	    vs_phase =10;
	}
	break;

    case	10:	/* メニュー表示		*/
	vs_display_phase = 7;
	if( wait_timer( 60 ) ) {
	    if( select_menu() ) {
		switch( sel_no ) {
		case	0:	vs_phase =11;	break;
		case	1:	vs_phase =12;	break;
		case	2:	vs_phase =13;	break;
		default:	vs_phase =14;	break;
		}
		Na_StopBgm( 50 );
	    }
	}
	break;

    case	11:	/* リトライ		*/
	if( ( wipe_cont+=16 )> 480 ) {
	    fade_R = fade_G = fade_B = 0;
	    fade_A = fade_A_f = 255;
	    BG_color = 0;
	    vs_retry();
	}
	break;

    case	12:	/* ＶＳメニュー		*/
	wipe_cont+= 16;
	if( wipe_cont > 160 ) {
	    if( wipe_cont > 176 )	play_mode= P_SINGLE;
	    fade_R= fade_G= fade_B= 0;
	    BG_color= 0;
	    if( wipe_cont > 160+ 64 )	vs_menu();
	}
	break;
	
    case	13:	/* ＥＮＤ		*/
	wipe_cont+= 16;
	if( wipe_cont > 160 ) {
	    if( wipe_cont > 176 )	play_mode= P_SINGLE;
	    fade_R= fade_G= fade_B= 0;
	    BG_color= 0;
	    if( wipe_cont > 160+ 64 ) {
		Game_Reset();
		title_return = 1;
	    }
	}
	break;

    case	14:	/* その他		*/
	break;

    case	20:	/* コントローラ警告	*/
	vs_display_phase = 9;
//	if( Key_T[ 0].button & CONT_B )	vs_phase = 13;
	if( Pad_T->button & CONT_B )	vs_phase = 13;
	else	vs_controller_warning_ctrl();
	break;
    }
    if( ( vs_phase==8 )||( vs_phase==9 )||( vs_phase==10 ) )	vs_frcnt += 1;
    if( vs_phase >= 5 ) {
	Pause_Ok = 0;  /* ポーズできません */
    }
    return( 0 );
}

/******************************************************************/
/*	ＶＳ仕様メイン（制御る〜ちん）				  */
/******************************************************************/
int	vs_game_observer( void )
{
    if( game_mode!=PAUSE )	vs_observ();
    return( 0 );
}
    
/******************************************************************/
/*	ＶＳ仕様メイン（表示る〜ちん）				  */
/******************************************************************/
void	vs_display( void )
{
    int		wipe_c;	/* ワイプの大きさ	*/
    
    vs_m_cmp= vs_m_sec;
    vs_m_sec= osGetTime();
    
    switch( vs_display_phase ) {
	
    case	 1:	machine_select_disp();	break;

    case	 2:	count_down_disp();	break;

    case	 7:	
    case	 6:	menu_window_disp( window_0_scl, window_1_scl );
    case	 5:
	switch( VS_game_mode ) {
	case	0:	/* ポイントマッチ	*/
	    vs_star_disp( wincnt, winner ); 
	    break;

	case	2:	/* タイムバトル	*/
	    TB_result_disp();
	    break;

	default:
	    break;
	}
	
    case	 4:
	if( ( VS_game_mode!=2 )||( !( vs_frcnt&32 ) ) ) {
	    if( winner< 4 )	win_message_disp();
	}

    case	 3:	
	winner_name_disp( win_msge_add_x, win_msge_scl, winner );
	if( vs_display_phase==7 )	select_menu_disp();
	break;
	
    case	10:	/* タイムトライアル用	*/
	vs_score_disp();
	
    case	 8:
	warning_disp();
	vs_retry_wait_disp();
	
    case	11:	/* タイムトライアル用	*/
	if( VS_game_mode==2 )	clock_disp( 124.0f, 116.0f, clock_time );
	break;

    case	 9:
	vs_controller_warning_disp();
	break;

    default:	break;
	
    }
    if( ( wipe_c=wipe_cont )>= 121 )	wipe_c= 121;
    fade_out( FADE_TATE, wipe_c );
}

/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	ＶＳ制御処理						┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
void	VS_manu( void )
{
    switch( option_mode ) {
	
    case	VS_WAIT:
	if(!system_time) {
	    option_mode	= VS_INIT;
	    Back_star_f	= 0;
	}
	break;

    case	VS_INIT:
	option_mode	= VS_MAIN;
	break;

    case	VS_MAIN:
	display_mode	= DISPLAY_NOTH;
	
	display_initial();
	
#if (FOX_DEBUG >= 3)
	if(Key[0].button & CONT_G) {
	    VS_stage	= 0;
	    if(Key[0].button & CONT_R) {
		VS_stage	= 1;
	    }
	    if(Key[0].button & CONT_L) {
		VS_stage	= 2;
	    }
	}
#endif
	if(VS_stage == 2)
	    Dma_No = 1; 
	
	mapno		= VS_01;
	system_mode	= GAME;
	system_time	= 2;
	game_mode	= GAME_WAIT;
	vs_time = 0;
	break;
    }
    frcnt += 1;
}

/*┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓*/
/*┃	ＶＳ表示処理						┃*/
/*┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛*/
void	VS_manu_display( void )
{
}
/*----------------------------------------------------------------*/
int vs_enemy_yama_check(ENMS *Enm, float sfy, float cfy)
{
    float x,z;
    
    x = sfy * 650.0f;
    z = cfy * 650.0f;
    
    if(fabsf(Enmb[0].obj.pos.x - (Enm->obj.pos.x+x)) < 1500.0f)  {
	if(fabsf(Enmb[0].obj.pos.z - (Enm->obj.pos.z+z)) < 1500.0f)  {
	    if(fabsf(Enmb[0].obj.pos.y - (Enm->obj.pos.y)) < 700.0f)  {
		return 1;
	    }
	}
    }
    return 0;
}
/*----------------------------------------------------------------*/
/* スターウルフ Enm->fwork[?] */
#define WOLF_BASE_SPD    0  /* 基本スピード */
#define WOLF_BASE_SPD_S  1  /* 基本スピード 目標 */
#define WOLF_TURN_SPD    2  /* ターンスピード */
#define WOLF_TURN_SPD_S  3  /* ターンスピード 目標 */
#define WOLF_TARGET_X    4
#define WOLF_TARGET_Y    5
#define WOLF_TARGET_Z    6
#define QUICK_Z          7  /* クイックZ回転 */
#define QUICK_Z_M        8  /* クイックZ回転 方向 */
#define BOOST_SPD        9  /* ブーストスピード */
#define BOOST_SPD_S      10 /* ブーストスピード目標 */

#define SHOCK_P            8

#define DAM_ZS     12 /* ダメージはねかえりスピード Z  （ウルフ専用） */
#define DAM_XS     13 /* ダメージはねかえりスピード X */
#define DAM_YS     14 /* ダメージはねかえりスピード Y */
/*----------------------------------------------------------------*/
void vs_enemy_move(ENMS *Enm)
{
    int cross,sh,i,j;
    float range1,range2;
    float range_X,range_Z;
    float x,y,z;
    float xa,ya,za;
    float px,py,pz;
    float sfx,sfy,cfx,cfy;
    xyz_t mae, ato, espd;
    SONIC *Snc;

/*---------------------------------------------*/
    sh = 0;  /* 軌道演算スイッチ */
    
    switch(Enm->stat) {
/* -------------------------------------------------------------*/	
    case  0: /* 特定のとこに集まる */
	sh = 1;

	if(Enm->time0 == 0) {
	    y = rnd() * 1000.0f;
	    x = (rnd()-0.5f) * 10000.0f;
	    z = (rnd()-0.5f) * 10000.0f;
	    
	    if(fabsf(Enm->obj.pos.x - x) > 2000.0f || fabsf(Enm->obj.pos.z - z) > 2000.0f) { /* ポイントが近かったらだめ */
		Enm->fwork[WOLF_TARGET_X] = x;
		Enm->fwork[WOLF_TARGET_Y] = y;
		Enm->fwork[WOLF_TARGET_Z] = z;
		Enm->time0 = (int)(rnd() * 20.0f) + 10;
	    }
	}
	break;
/* -------------------------------------------------------------*/	
    }
    
    sfx = sinf(ANGLE(Enm->obj.ang.x));
    cfx = cosf(ANGLE(Enm->obj.ang.x));
    sfy = sinf(ANGLE(Enm->obj.ang.y));
    cfy = cosf(ANGLE(Enm->obj.ang.y));
    
    if(sh)  {
/* ターゲットに接近 */    
	x = Enm->fwork[WOLF_TARGET_X] - Enm->obj.pos.x;
	y = Enm->fwork[WOLF_TARGET_Y] - Enm->obj.pos.y;
	z = Enm->fwork[WOLF_TARGET_Z] - Enm->obj.pos.z;
	
	if( ! ((frcnt+Enm->index) & 0x07)) {
	    Enm->fwork[HEAD_YA] = rad_ang((fatan3(x,z)));
	
	    z = sqrtf(x*x + z*z);
	    Enm->fwork[HEAD_XA] = rad_ang((fatan3(y,z)));
	}

	xa = Enm->fwork[HEAD_XA];
//	ya = Enm->fwork[HEAD_YA];
	
	cross = vs_enemy_yama_check(Enm, sfy, cfy);
	
	if( cross ) {
	    xa += 40.0f * (float)cross;
	    
	    if(xa >= 360.0f)
		xa -= 360.0f;
	    if(xa <  0.0f)
		xa += 360.0f;
	    
	} else if(Enm->obj.pos.y < GYPOSF+50.0f /*&& STAGE == GROUND*/) {
	    if(xa > 180.0f) {
		xa = 0.0f;
		Enm->MXang = 0.0f;
	    }
	}
	
	add_calc_a(&Enm->MXang, xa, 0.5f, 1.0f, 0.0001f);
	za = add_calc_a(&Enm->MYang, Enm->fwork[HEAD_YA], 0.5f, 1.0f, 0.0001f) * 30.0f;
	
	if(za < 0.0f) {
	    za *= -1.0f;
	} else {
	    za = 360.0f - za;
	}
	
	add_calc_a(&Enm->obj.ang.z, za, 0.1f, 3.0f, 0.01f);
    }
    
    Enm->obj.ang.x = -Enm->MXang;
    Enm->obj.ang.y = Enm->MYang;
    
    
    ato.z =  cfx * 38.0f;
    ato.y = -sfx * 38.0f;

    ato.x = sfy * ato.z;
    ato.z = cfy * ato.z;
    
    Enm->Xspd =  ato.x + Enm->fwork[DAM_XS];
    Enm->Yspd =  ato.y + Enm->fwork[DAM_YS];
    Enm->Zspd =  ato.z + Enm->fwork[DAM_ZS];

    Enm->fwork[DAM_XS] -= Enm->fwork[DAM_XS] * 0.1f;
    Enm->fwork[DAM_YS] -= Enm->fwork[DAM_YS] * 0.1f;
    Enm->fwork[DAM_ZS] -= Enm->fwork[DAM_ZS] * 0.1f;
    
    if(Enm->obj.pos.y < GYPOSF + 40.0f &&
       Enm->Yspd < 0.0f /*&&
       STAGE == GROUND*/) {
	
	Enm->obj.pos.y = GYPOSF + 40.0f;
	Enm->Yspd = 0.0f;
    }

    wolf_damage_check(Enm);
#if 0    
/*  レーダー表示 */ 
    Snc  = &Sonic[Enm->index];
    
    Snc->mode  = 1;
    Snc->num   = Enm->p_NO;
    Snc->pos.x = Enm->obj.pos.x;
    Snc->pos.y = Enm->obj.pos.y;
    Snc->pos.z = Enm->obj.pos.z;
    Snc->Yang  = Enm->MYang+180.0f;
#endif    
    
    if(Enm->work[SHOCK_P])  /* ？ */
	Enm->work[SHOCK_P] -- ;     /* 衝撃反動タイム */
}

/*+=====================================================================+
  |	VS KT敵総合制御                                     		|
  +=====================================================================+*/
#define VS_ENEMY_MAX (5)
void vs_cont(void)
{
    int i;
    xyz_t mae,ato;
    ENMS *Enm2;

    if(VS_game_mode!=2 || !VS_start)
	return;

    if(vs_time)
	vs_time --;

    if(!vs_time)  {  /*  */
	vs_time = 2;
    
	mae.x =  0.0f;
	mae.y =  500.0f;
	mae.z =  -10000.0f;
	
	for(i=0,Enm2=&Enms[10];i<VS_ENEMY_MAX;i++,Enm2++) {
	    if(Enm2->obj.mode == ENOTH  /*&& sonic_YA[i + 8 + 1] < 1000.0f*/)  {
		enms_ram_clear(Enm2); 
		Enm2->obj.mode = EMOVE;
		Enm2->obj.num = WOLF;

		rotateY_work(ANGLE(rnd()*360.0f), SET_MTX);
	
		MtxF_PositionRS_work(&mae, &ato);
		
		Enm2->obj.pos.x = ato.x;
		Enm2->obj.pos.y = ato.y;
		Enm2->obj.pos.z = ato.z;
		Enm2->p_NO  = i + 10;
		Enm2->life = 24;
		Enm2->timeP = 30;
		Object_adress_set(&Enm2->adr,  Enm2->obj.num);
//		Na_StartEnemySe(Enm2->sound_ps, NA_SE_ARWING_ENGINE_F);
		Enm2->adr.M_adress = (void (*)(ENMS *))vs_enemy_move;
		break;
	    }
	}
    }
}

