/*
	キャラの動作ルーチン（リファレンス出来るレベルにしたいなぁ）
	即時リターンする場合は動作種類の優先順位が重要
	例えば･･･
	高優先
		特殊飛び道具の処理
		ダメージ、ガード処理
		システムが要求するポーズ等
		向き変え（キャンセルしても可）
		--此処以降はキャンセルＯＫ時--
		特殊な必殺技
		コマンドが複雑な必殺技
		コマンドが簡単な必殺技
		--此処以降は動作ＯＫ時--
		ジャンプ攻撃
		二段ジャンプ、三角飛び
		斜めジャンプ
		垂直ジャンプ
		通常技
		移動など
		ニュートラル
	低優先
	
	ま、パズルみたいなものですね、これは。
	整理しないとデッドロックしちゃいます。
	動作属性の通知さえちゃんとやればどんな組み方でもＯＫ
*/


#include <stdrr.h>
#include <math.h>
#include "game.h"
#include "global.h"
#include "function.h"

#include "shinobu.h"


/**** 展開型関数 ****/
/* 向き変え */
#define direction_check()  \
	if( INFO.pos_x>YOU.pos_x ) INFO.direction = -1;\
	if( INFO.pos_x<YOU.pos_x ) INFO.direction =  1

/* 移動方向変え */
/*
#define dir_negation(argi)  \
	if( INFO.direction<0 ) (argi) *= -1
*/

/* 引き数に向きを考慮したベクトル操作を与える */
/* キャラ相対ベクトルからシステム絶対ベクトルへの変換でもある */
#define vect_effect(argi)  \
	if( INFO.direction<0 ) (argi) *= -1



/*
#define dir_negation_you(argi)  \
	if( YOU.direction>0 ) (argi) *= -1
*/

/* リバサ */
#define set_reversal()  \
	INFO.rev_time = 200;\
	INFO.inv_time = 200

/**** コマンド定義 ****/
/* キャラ毎にレスポンスを変えても面白いかも */
/* 前 */
/*
#define COMMAND_F												\
	(((CommandBuff[player][0]&PAD_RIGHT)&&(INFO.pos_x<YOU.pos_x)) ||	\
	 ((CommandBuff[player][0]&PAD_LEFT )&&(INFO.pos_x>YOU.pos_x)) )
*/
#define COMMAND_F												\
	(((CommandBuff[player][0]&PAD_RIGHT)&&(INFO.direction>0)) ||	\
	 ((CommandBuff[player][0]&PAD_LEFT )&&(INFO.direction<0)) )

/* 後ろ */
/*
#define COMMAND_B												\
	(((CommandBuff[player][0]&PAD_LEFT )&&(INFO.pos_x<YOU.pos_x)) ||	\
	 ((CommandBuff[player][0]&PAD_RIGHT)&&(INFO.pos_x>YOU.pos_x)) )
*/
#define COMMAND_B												\
	(((CommandBuff[player][0]&PAD_LEFT )&&(INFO.direction>0)) ||	\
	 ((CommandBuff[player][0]&PAD_RIGHT)&&(INFO.direction<0)) )

/* 後ろ(ガードベクトル) */
#define COMMAND_BV												\
	(((CommandBuff[player][0]&PAD_LEFT )&&(YOU.direction<0)) ||		\
	 ((CommandBuff[player][0]&PAD_RIGHT)&&(YOU.direction>0)) ||		\
	 (INFO.auto_guard) )

/* 上 */
#define COMMAND_U											\
	(CommandBuff[player][0]&PAD_UP)

/* 下 */
#define COMMAND_D											\
	(CommandBuff[player][0]&PAD_DOWN)


/*int shinobu_act(int player)*/
int shinobu_act(int *spr_top, int *smem_top, int player)
{
	static int mv[2];						/* 汎用						*/
	static int m_count[2];					/* マスターカウンタ			*/
	int i,j;								/* 汎用						*/
	int you;
	/*int val_a,val_b;*/
	
	
	
	/* init */
	if( player<0 ){
		
		for(player=0; player<2; player++){
			lah_laser(player, 2);
			INFO.motion = 0;
			
			/* 超テスト */
			INFO.atk_vect_x = 100;
			INFO.atk_vect_y = -50;
		}
		return;
	}
	
	
	/* コマンド読み込み */
	if( INFO.com_player )
		com_shinobu(player);
	else
		pad_read(player, 0);
	
	
	
	you = !player;
	
	/*val_a = read_val(player,1);*/			/* ボタンの強弱の読み取り */
	/*val_b = read_val(player,2);*/			/* ボタンの強弱の読み取り */
	
	
	resetGuardOk();
	
	
	/* 影てすと */
	flushShadowRun(player);
	
	
	/* 特殊飛び道具の処理 */
	lah_laser(player, 0);
	
	
	
	
	
	/* ダメージ（のけぞり系） */
	if( DAMAGE ){
		
		static int	dpow;
		
		
		resetAction();		/* ローカル */
		
		
		/* ダウン系 */
		if( INFO.motion&(DAM_DOWN|DAM_FUKI|DAM_KOKE|DAM_KO) ){
			if( INFO.move_count==0 ){
				INFO.move_count	 = speed;	/* loop trap */
				INFO.count_sys	 = 0;
				JUMP.flag		 = 1;
				/*JUMP.x_add		 = -16;*/
				JUMP.y_ofs		 = INFO.pos_y-32*POS_DEC;
				JUMP.velocity	 = 120;
				JUMP.gravity	 = 26;
				INFO.ptr_set	 = 0;
				INFO.ptr_no		 = 2;
				if( INFO.motion&DAM_DOWN )
					voice_play(player, 9);
				else
					voice_play(player, 3);
				if( INFO.motion&DAM_KO )
					voice_play2(player, 4, 10);	/* 時間差断末魔 */
				
				flushShadowReset(player);
			}
			
			
			
			/* 吹き飛ぶ */
			if( JUMP.move_vect )
				INFO.ptr_no = 3;
			else
				INFO.ptr_no = 2;
			
			
			/* 高度によって影のサイズをかえる */
			INFO.shadow_size = INFO.pos_y/(POS_DEC*2);
			
			
			/* 地面に叩きつけられる */
			if( JUMP.flag==0 ){
				DAMAGE_reset();
				DAMAGE2_set();
				INFO.pos_y = (ground+10)*POS_DEC;
				return;
			}
			
			return;
		}
		
		/*
		if( INFO.move_count==0 ){
			
			voice_play(player, 3);
		}
		*/
		
		INFO.ptr_set = 0;
		
		INFO.move_count += speed;
		
		
		
		
		/* 鼻血 */
		if( INFO.motion&DAM_HANA ){
			INFO.ptr_no = 1;
			
			DECO(0).use_flag = 1;
			DECO(0).ptr_set = 4;
			DECO(0).pos_x = INFO.pos_x;
			DECO(0).pos_y = INFO.pos_y;
			DECO(0).direction = INFO.direction;
			DECO(0).pal = PAL_CHAR(player, 9);
			DECO(0).twinkle = 0;
			
			if( INFO.move_count<70 ){
				DECO(0).ptr_no = 0;
				return 0;
			} else if( INFO.move_count<140 ){
				DECO(0).ptr_no = 1;
				return 0;
			} else if( INFO.move_count<200 ){
				DECO(0).ptr_no = 2;
				return 0;
			}
			
			DECO(0).use_flag = 0;
			INFO.motion &= ~DAM_HANA;
		}
		
		/* ゲロ */
		if( INFO.motion&DAM_GERO ){
			INFO.ptr_no = 0;
			
			DECO(0).use_flag = 1;
			DECO(0).ptr_set = 4;
			DECO(0).pos_x = INFO.pos_x;
			DECO(0).pos_y = INFO.pos_y;
			DECO(0).direction = INFO.direction;
			DECO(0).pal = PAL_CHAR(player, 9);
			DECO(0).twinkle = 0;
			
			if( INFO.move_count<50 ){
				DECO(0).ptr_no = 3;
				return 0;
			} else if( INFO.move_count<100 ){
				DECO(0).ptr_no = 4;
				return 0;
			} else if( INFO.move_count<150 ){
				DECO(0).ptr_no = 5;
				return 0;
			} else if( INFO.move_count<200 ){
				DECO(0).ptr_no = 6;
				return 0;
			}
			
			DECO(0).use_flag = 0;
			INFO.motion &= ~DAM_GERO;
		}
		
		
		if( INFO.move_count<180 ){				/* ここの時間が超重要 */
			INFO.ptr_no = 0;
			
		} else if( INFO.move_count<250 ){
			INFO.ptr_no = 1;
			
		} else {
			INFO.ptr_no = 1;
			/*INFO.motion = 0;*/
			DAMAGE_reset();
			set_reversal();
			INFO.move_count = 0;
		}
		
		/*INFO.move_count += speed;*/
		return 0;
	}
	/* ダメージ(叩きつけられてから起き上がるまで) */
	if( DAMAGE2 ){
		
		INFO.count_sys += speed;
		INFO.ptr_set	 = 0;
		INFO.shadow_size = 120;
		
		/* 優先順に並べて即リターンする必要有り */
		
		/* KO */
		if( INFO.motion&DAM_KO ){
			if( INFO.count_sys<200 ){
				INFO.pos_y -= speed*16;
				INFO.ptr_no = 3;
			} else if( INFO.count_sys<400 ){
				INFO.pos_y += speed*16;
				INFO.ptr_no = 2;
			} else if( INFO.count_sys<600 ){
				INFO.pos_y -= speed*8;
				INFO.ptr_no = 3;
			} else if( INFO.count_sys<800 ){
				INFO.pos_y += speed*8;
				INFO.ptr_no = 2;
			} else {
				INFO.ptr_no = 3;
			}
			return;
		}
		
		/* ダウン */
		if( INFO.motion&DAM_DOWN ){
			if( INFO.count_sys<200 ){
				INFO.pos_y -= speed*16;
				INFO.ptr_no = 3;
			} else if( INFO.count_sys<400 ){
				INFO.pos_y += speed*16;
				INFO.ptr_no = 2;
			} else if( INFO.count_sys<600 ){
				INFO.pos_y -= speed*8;
				INFO.ptr_no = 3;
			} else if( INFO.count_sys<800 ){
				INFO.pos_y += speed*8;
				INFO.ptr_no = 2;
			} else if( INFO.count_sys<1500 ){
				/*INFO.pos_y  = (ground+10)*POS_DEC;*/
				INFO.ptr_no = 3;
			} else {
				INFO.motion = 0;
				INFO.pos_y  = ground*POS_DEC;
				set_reversal();
			}
			return;
		}
		
		/* 転倒と吹き飛び(今のところ同じ扱い) */
		if( INFO.motion&(DAM_KOKE|DAM_FUKI) ){
			if( INFO.count_sys<200 ){
				INFO.pos_y -= speed*8;
				INFO.ptr_no = 3;
			} else if( INFO.count_sys<400 ){
				INFO.pos_y += speed*8;
				INFO.ptr_no = 2;
			} else {
				INFO.motion = 0;
				INFO.pos_y  = ground*POS_DEC;
				set_reversal();
			}
			return;
		}
		
		return;
	}
	
	
	/***	此処からはコマンド必殺技(キャンセル可)	***/
	
	
	
	/* 昇龍拳もどき(新システム対応) */
	if( ACTION_S_SHOU ){
		
		if( chkAction(S_SHOU) ){
			
			setAction(S_SHOU);
			
			
			/* システム通知 */
			ALLMOTION_reset();
			ATTACK_set();
			INFO.attack		 = ATK_DB;
			prior			 = player;
			
			
			/* ローカルセット */
			INFO.move_count	 = 0;
			INFO.count_a	 = 400;		/* 垂直ジャンプの項を見よ */
			INFO.count_c	 = 1;		/* フラグとして使用します */
			INFO.count_d	 = 1;		/* フラグとして使用します */
			INFO.hit_limit	 = 2;
			
			
			INFO.mov_val = 40;
			if( BUTTON(PAD_X) ){
				INFO.mov_val += 20;
			}
			if( BUTTON(PAD_Y) ){
				INFO.mov_val += 80;
			}
			if( BUTTON(PAD_Z) ){
				INFO.mov_val += 140;
				INFO.hit_limit = 5;
				INFO.inv_time = 800;		/* 無敵時間 */
			}
			
			if( INFO.sprit_on ){
				INFO.sprit_energy = 0;
				voice_play(player, 8);
				INFO.hit_limit = 30;			/* べらぼうだ */
			} else {
				INFO.sprit_energy += 15000;
				if( INFO.mov_val>=140 )
					voice_play(player, 7);
				else
					voice_play(player, 6);
			}
			
			
			/* この初期化は最後にしなくてはいけないらしい */
			pad_read(player, 1);
			
		}
		
		
		INFO.ptr_set = 13;
		
		
		if( INFO.move_count<150 ){
			INFO.ptr_no = 0;
			
			
			
		} else if( INFO.move_count<300 ){
			INFO.ptr_no = 1;
			
			if( INFO.count_c ){
				INFO.count_c = 0;
				i = 32*POS_DEC;
				vect_effect(i);
				INFO.pos_x += i;
			}
			
			i = is_hit(player);
			if( (i)&&(INFO.hit_limit) ){
				INFO.hit_limit--;
				guard_check(you, i, 9*128, 2*128);
				freeze_time = 6;
			}
			
			
			
		} else /*if( INFO.move_count<1000 ){*/
			if( JUMP.move_y<=0 ){	/* 上昇中 */
			
			INFO.ptr_no = 2;
			
			if( INFO.count_d ){
				INFO.count_d = 0;
				
				/* 上昇ベクトル指定 */
				INFO.motion		|= JMP_VER;			/* 下降はコレで代用 */
				INFO.count_a	 = 0;
				JUMP.flag		 = 1;
				JUMP.x_add		 = INFO.mov_val/8 /*20*/;
				JUMP.y_ofs		 = INFO.pos_y/*0*/;
				JUMP.velocity	 = INFO.mov_val;
				JUMP.gravity	 = GRV;
				JUMP.direction	 = INFO.direction;
				
				/* 影を付けよう */
				if( INFO.mov_val>=140 ){
					flushShadowSet(player, 1000, 1);
				}
			}
			
			
			i = is_hit(player);
			if( (i)&&(INFO.hit_limit) ){
				INFO.hit_limit--;
				guard_check(you, i, 4*128, 2*128);
				freeze_time = 6;
			}
			
			
		} else {
			resetAction();
			INFO.move_count	= 0;
			INFO.count_d	= 0;
			INFO.attack		= 0;
			ATTACK_reset();
			/*INFO.ptr_no		= 0;*/
			return;
			
		}
		
		
		INFO.move_count += speed;
		
		
		return;
	}
	
	
	
	
	
	
	
	
	
	/* タマ（爆笑） */
	if( (ATTACK&&DEATH)||(COMMAND_TAMA) ){
		if( !ATTACK ){
			ALLMOTION_reset();
			ATTACK_set();
			INFO.attack		 = ATK_DB;
			/*INFO.attack		|= ATK_BRT;*/
			INFO.move_count	 = 0;
			INFO.hit_limit	 = 1;
			mv[player]		 = 0;
			prior			 = player;
			i = 0;
			pad_read(player, 1);
			
			if( INFO.sprit_on ){
				INFO.sprit_energy = 0;
				voice_play(player, 5);
				mv[player] = 500;
				INFO.attack |= ATK_POW4;
				i = 1;
			} else {
				INFO.sprit_energy += 15000;
				voice_play(player, 2);
			}
			
			
			INFO.mov_val = 40;
			if( BUTTON(PAD_X) )
				INFO.mov_val += 40;
			if( BUTTON(PAD_Y) )
				INFO.mov_val += 40;
			if( BUTTON(PAD_Y) )
				INFO.mov_val += 40;
			
			
			
			
			if(i)
				shinobu_tama(player, -1);
			else
				shinobu_tama(player, 3);
			
		}
		
		INFO.move_count += speed;
		
		INFO.ptr_set = 3;
		
		if( INFO.move_count<100 ){
			INFO.ptr_no = 0;
			
		} else if( INFO.move_count<500 ){
			INFO.ptr_no = 1;
			
		} else {
			INFO.move_count	= 0;
			INFO.attack		= 0;
			ATTACK_reset();
			INFO.ptr_no		= 0;
			return;
		}
		
		return;
	}
	/* lah */
	if( (INFO.sprit_on)&&(COMMAND_LAH)&&(INFO.life<INFO.super) ){
		INFO.sprit_energy = 0;
		pad_read(player, 1);
		if( lah_laser(player, 1) )
			side_bonus(0, player, 5, 0);
		return;
	}
	/* フォース */
	if( (CommandBuff[player][0]&PADs_C)&&INFO.com_player ){
		shinobu_force(player, 1);
		return;
	}
	
	
	
	
	
	/***	此処以降は通常キャンセルは不可(目押しは可)	***/
	/* システムからガードヒット通告された場合 */
	if( GUARD ){
		
		if( CROUCH ){
			INFO.ptr_set = 8;
			INFO.ptr_no = 1;
		} else {
			INFO.ptr_set = 10;
			INFO.ptr_no = 0;
		}
		
		INFO.move_count += speed;
		if( INFO.move_count>400 ){
			INFO.ptr_no = 0;
			INFO.motion = 0;
			INFO.move_count = 0;
			set_reversal();
		}
		
		return;
	}
	/* ガード取消 */
	/*INFO.motion &= ~MOV_DEF;*/
	
	
	
	
	
	
	/** 此処以降はジャンプ系 **/
	
	/* ジャンプ中キック */
	if( FRYING&&((ATTACK&&KICK&&POWER2)||(BUTTON(PADs_A|PADs_B))) ){
		
		INFO.ptr_set = 11;
		if( !ATTACK ){
			ATTACK_set();
			INFO.attack		 = ATK_KICK;
			INFO.attack		|= ATK_POW2;
			INFO.attack		|= ATK_NG_CRU;		/* しゃがみ防御不能 */
			INFO.count_b	 = 0;
			INFO.hit_limit	 = 2;
			mv[player]		 = 0;
			prior			 = player;
			voice_play(player, 1);
		}
		
		
		if( INFO.count_b<30 ){
			INFO.ptr_no = 0;
			
		} else if( INFO.count_b<270 ){
			INFO.ptr_no = 0;
			i = is_hit(player);
			if( (i)&&(INFO.hit_limit) ){
				INFO.hit_limit--;
				if( JUMP.move_vect )
					guard_check(you, i, 6*128, 128);	/* 昇りは攻撃力小 */
				else
					guard_check(you, i, 9*128, 2*128);
				mv[player] = 100;				/* この時間だけ硬直する */
				freeze_time = 6;
				INFO.attack |= CANCEL_DB;
				INFO.attack |= CANCEL_SDB;
			}
			
		} else if( INFO.count_b<270+mv[player] ){	/* 硬直中 */
			INFO.attack |= CANCEL_EYE;
			
		} else if( INFO.count_b<300+mv[player] ){
			INFO.ptr_no = 0;
			INFO.attack &= ~CANCEL_EYE;			/* 目押し解除 */
			
		} else {
			INFO.count_b	= 0;
			INFO.attack		= 0;
			ATTACK_reset();
			/*INFO.motion     = 0;*/
			INFO.ptr_no		= 0;
			return;
		}
		
		INFO.count_b += speed;
		return;
	}
	
	
	
	/* 八艘飛び */
	/*
	if( (INFO.motion&(JMP_FRT|JMP_RDY))||(COMMAND_U&&COMMAND_F) ){
		
		if( !(INFO.motion&(JMP_RDY|JMP_FRT)) ){
			INFO.motion		|= JMP_RDY;
			INFO.count_a	 = 0;
			JUMP.x_add		 = 200;
			JUMP.y_ofs		 = INFO.pos_y;
			JUMP.velocity	 = 600;
			JUMP.gravity	 = GRV;
			JUMP.direction	 = INFO.direction;
			sdw_cnt[player]  = 500;
			direction_check();
			/ *dir_negation(JUMP.x_add);* /
		}
		
	}
	*/
	
	
	
	
	/* 新ガードシステム */
	setGuardOk(G_OK_SKY);
	setGuardOk(G_OK_UP);
	setGuardOk(G_OK_MID);
	
	
	
	
	
	
	
	
	/* 前方ジャンプ */
	if( (INFO.motion&JMP_FRT)||((COMMAND_U&&COMMAND_F)&&(!FRYING)) ){
		
		/* 初期化 */
		if( !(INFO.motion&JMP_FRT) ){
			INFO.motion		|= JMP_FRT;
			INFO.count_a	 = 0;
			JUMP.x_add		 = 20;
			JUMP.y_ofs		 = INFO.pos_y/*0*/;
			/*JUMP.time		 = 0;*/
			JUMP.velocity	 = 120;
			JUMP.gravity	 = GRV;
			JUMP.direction	 = INFO.direction;
			direction_check();
			/*dir_negation(JUMP.x_add);*/
			if( CommandBuff[player][0]&PAD_B ){
				flushShadowSet(player, 1000, 0);
				JUMP.velocity	 = 200;
			}
		}
		
		
		INFO.count_a += speed;
		
		if( INFO.count_a<120 ){
			/* 構え */
			mv[player] = 0;
			INFO.ptr_set = 8;					/* しゃがみポーズ */
			INFO.ptr_no = 0;
			INFO.shadow_size = 64;
			
		} else if( INFO.count_a<360 ){
			/* ジャンプ開始 */
			INFO.motion	|= MOV_SKY;
			JUMP.flag	 = 1;
			INFO.ptr_set = 6;
			INFO.ptr_no  = 0;
			INFO.shadow_size -= speed/8;
			
		} else if( INFO.count_a<420 ){
			/* 上昇中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 0;
			INFO.shadow_size -= speed/8;
			
		} else if( INFO.count_a<460 ){
			/* 上昇中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 1;
			INFO.shadow_size -= speed/8;
			
		} else if( INFO.count_a<500 ){
			/* 下降中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 2;
			/*INFO.shadow_size += speed/30;*/
			
		} else if( INFO.count_a<540 ){
			/* 下降中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 3;
			/*INFO.shadow_size += speed/30;*/
			
		} else {
			/* 下降中2 */
			INFO.ptr_set = 6;
			INFO.ptr_no = 2;
			INFO.shadow_size += speed/8;
			
		}
		return;
	}
	
	/* 後方ジャンプ */
	if( (INFO.motion&JMP_BAK)||((COMMAND_U&&COMMAND_B)&&(!FRYING)) ){
		
		/* 初期化 */
		if( !(INFO.motion&JMP_BAK) ){
			INFO.motion		|= JMP_BAK;
			INFO.count_a 	 = 0;
			JUMP.x_add		 = -20;
			JUMP.y_ofs		 = INFO.pos_y/*0*/;
			/*JUMP.time		 = 0;*/
			JUMP.velocity	 = 120;
			JUMP.gravity	 = GRV;
			JUMP.direction	 = INFO.direction;
			direction_check();
			/*dir_negation(JUMP.x_add);*/
			/* test */
			if( CommandBuff[player][0]&PAD_B ){
				flushShadowSet(player, 1000, 0);
				JUMP.velocity	 = 200;
			}
		}
		
		
		INFO.count_a += speed;
		
		if( INFO.count_a<120 ){
			/* 構え */
			mv[player] = 0;
			INFO.ptr_set = 8;					/* しゃがみポーズ */
			INFO.ptr_no = 0;
			INFO.shadow_size = 64;
			
		} else if( JUMP.sys_time<(360-120) ){
			/* ジャンプ開始 */
			INFO.motion	|= MOV_SKY;
			JUMP.flag	 = 1;
			INFO.ptr_set = 6;
			INFO.ptr_no  = 0;
			INFO.shadow_size -= speed/8;
			
		} else if( /*INFO.count_a*/JUMP.sys_time<(420-120) ){
			/* 上昇中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 4;
			INFO.shadow_size -= speed/8;
			
		} else if( /*INFO.count_a*/JUMP.sys_time<(460-120) ){
			/* 上昇中 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 5;
			INFO.shadow_size -= speed/8;
			
		} else if( /*INFO.count_a*/JUMP.sys_time<(500-120) ){
			/* 下降中1 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 6;
			/*INFO.shadow_size += speed/30;*/
			
		} else if( /*INFO.count_a*/JUMP.sys_time<(540-120) ){
			/* 下降中1 */
			INFO.ptr_set = 7;
			INFO.ptr_no = 7;
			/*INFO.shadow_size += speed/30;*/
			
		} else {
			/* 下降中2 */
			INFO.ptr_set = 6;
			INFO.ptr_no = 2;
			INFO.shadow_size += speed/8;
			
		}
		return;
	}
	
	
	/* 垂直ジャンプ */
	if( (INFO.motion&(JMP_VER|JMP_RDY))||COMMAND_U ){
		
		/*	JUMP.time が JUMP.vero/2GRV になった時が頂点になる筈です
			適当に逆算してパターンを決定する必要があります	*/
		
		/* 初期化 */
		if( !(INFO.motion&(JMP_RDY|JMP_VER)) ){
			INFO.motion		|= JMP_RDY;
			INFO.count_a	 = 0;
			JUMP.x_add		 = 0;
			JUMP.y_ofs		 = INFO.pos_y/*0*/;
			/*JUMP.time		 = 0;*/
			JUMP.velocity	 = 124;
			JUMP.gravity	 = GRV;
			JUMP.direction	 = INFO.direction;
			direction_check();
			/* test */
			if( CommandBuff[player][0]&PAD_B ){
				flushShadowSet(player, 1000, 0);
				
				JUMP.velocity	 = 200;
			}
		}
		
		
		INFO.ptr_set = 6;
		INFO.count_a += speed;
		
		if( INFO.count_a<120 ){
			/* 構え */
			mv[player] = 0;
			INFO.ptr_set = 8;					/* しゃがみポーズ */
			INFO.ptr_no = 0;
			INFO.shadow_size = 64;
			
		} else if( INFO.count_a<360 ){
			/* ジャンプ開始 */
			if( !(INFO.motion&JMP_VER) ){
				INFO.motion	|= MOV_SKY;
				INFO.motion	|= JMP_VER;
				JUMP.flag	 = 1;

			}
			INFO.ptr_no = 0;
			INFO.shadow_size -= speed/8;
			
		} else if( INFO.count_a<420 ){
			/* 上昇中 */
			INFO.ptr_no = 1;
			INFO.shadow_size -= speed/8;
			
		} else if( INFO.count_a<520 ){
			/* 下降中1 */
			INFO.ptr_no = 1;
			/*INFO.shadow_size += speed/30;*/
			
		} else {
			/* 下降中2 */
			INFO.ptr_no = 2;
			INFO.shadow_size += speed/8;
			
		}
		return;
	}
	
	
	/* 新ガードシステム */
	resetGuardOk();
	/*unsetGuardOk(G_OK_UP);*/
	/*unsetGuardOk(G_OK_MID);*/
	
	
	
	
	
	/*** 此処からはしゃがみ動作 ***/
	
	/* しゃがみ小パンチ */
	if( CROUCH&&((ATTACK&&(PUNCH&&POWER1))||(BUTTON(PADs_X|PADs_Y))) ){
		
		INFO.ptr_set = 9;
		if( !ATTACK ){
			INFO.motion		|= MOV_ATK;
			INFO.attack		 = ATK_PUN;
			INFO.attack		|= ATK_POW1;
			/*INFO.attack		&= ~CANCEL_ALL;*/	/* キャンセル解除 */
			INFO.count_b	 = 0;
			mv[player]		 = 0;
			prior			 = player;
			INFO.shadow_size = 56;
			/* おまけ(高速めくり用) */
			direction_check();
			/*dir_negation(JUMP.x_add);*/
			voice_play(player, 0);
		}
		
		
		if( INFO.count_b<20 ){
			INFO.ptr_no = 0;
			
		} else if( INFO.count_b<60+mv[player] ){
			INFO.ptr_no = 1;
			INFO.attack |= CANCEL_DB;
			INFO.attack |= CANCEL_SDB;
			INFO.attack |= CANCEL_EYE;
			i = is_hit(player);
			if( (i)&&(mv[player]==0) ){
				guard_check(you, i, 6*128, 0);
				mv[player] = 120;				/* この時間だけ硬直する */
			}
			
		} else if( INFO.count_b<80+mv[player] ){
			INFO.ptr_no = 0;
			INFO.attack &= ~CANCEL_EYE;			/* 目押し解除 */
			
		} else {
			INFO.count_b	= 0;
			INFO.attack		= 0;
			INFO.motion     = 0;
			INFO.ptr_no		= 0;
			return;
		}
		
		INFO.count_b += speed;
		return;
	}
	
	/* しゃがみ(ガード含む) */
	/* しゃがみ導入もする */
	INFO.motion &= ~MOV_CRU;
	if( (!ATTACK)&&COMMAND_D ){
		
		
		/* 新ガードシステム */
		setGuardOk(G_OK_DOWN);
		setGuardOk(G_OK_MID);
		
		
		
		INFO.ptr_set = 8;
		INFO.ptr_no = 0;
		INFO.shadow_size = 54;
		INFO.motion |= MOV_CRU;
		direction_check();
		
		/* 相手が攻撃中なら防御(準備)する */
		/*
		if( (ATTACK_YOU||BRITZ_YOU)&&COMMAND_BV ){
			INFO.motion |= MOV_DEF;
			INFO.ptr_no = 1;
		} 
		*/
		
		return;
	}
	
	
	/* 新ガードシステム */
	resetGuardOk();
	
	
	
	/*** 此処からは地上立ち動作 ***/
	/* 大体ふるい落とされているからチェックは甘く */
	
	/* 遠距離弱パンチ */
	if( (ATTACK&&(PUNCH&&POWER1))||(BUTTON(PADs_X|PADs_Y)) ){
		
		if( !ATTACK ){
			INFO.motion		|= MOV_ATK;
			INFO.attack		 = ATK_PUN;
			INFO.attack		|= ATK_POW1;
			/*INFO.attack		&= ~CANCEL_ALL;*/		/* キャンセル解除 */
			INFO.count_b	 = 0;
			mv[player]		 = 0;
			prior			 = player;
			INFO.shadow_size = 66;
			/* おまけ(高速めくり用) */
			direction_check();
			/*dir_negation(JUMP.x_add);*/
			voice_play(player, 0);
		}
		
		INFO.ptr_set = 3;
		
		
		if( INFO.count_b<20 ){
			INFO.ptr_no = 0;
			
		} else if( INFO.count_b<60+mv[player] ){
			INFO.ptr_no = 1;
			INFO.attack |= CANCEL_DB;
			INFO.attack |= CANCEL_SDB;
			INFO.attack |= CANCEL_EYE;
			i = is_hit(player);
			if( (i)&&(mv[player]==0) ){
				guard_check(you, i, 6*128, 0);
				mv[player] = 120;
			}
			
		} else if( INFO.count_b<80+mv[player] ){
			INFO.ptr_no = 0;
			INFO.attack &= ~CANCEL_EYE;			/* 目押し解除 */
			
		} else {
			INFO.count_b	= 0;
			INFO.attack		= 0;
			INFO.motion     = 0;
			INFO.ptr_no		= 0;
			return;
		}
		
		INFO.count_b += speed;
		return;
	}
	
	
	
	/* 新ガードシステム */
	setGuardOk(G_OK_UP);
	setGuardOk(G_OK_MID);
	
	
	
	
	
	/* バックステップ */
	if( ACTION_BACKSTEP ){
		
		if( chkAction(BACKSTEP) ){
			
			setAction(BACKSTEP);
			pad_read(player, 1);
			
			
			/* システム通知 */
			/*ALLMOTION_reset();*/
			
			INFO.move_count	 = 0;
			flushShadowSet(player, 500, 0);
			/*INFO.inv_time = 500;*/
			
			
			/* グラフィック描いてないっす */
			INFO.ptr_set	= 1;
			INFO.ptr_no		= 0;
		}
		
		
		if( INFO.direction<0 )
			INFO.pos_x += 50*speed;
		else
			INFO.pos_x -= 50*speed;
		
		INFO.move_count += speed;
		if( INFO.move_count>500 ){
			INFO.move_count = 0;
			resetAction();
		}
		
		return;
	}
	
	
	
	
	
	
	
	/* ガード */
	/*
	if( (!ATTACK)&&(COMMAND_BV&&(ATTACK_YOU||BRITZ_YOU)) ){
		
		INFO.ptr_set = 10;
		INFO.ptr_no = 0;
		INFO.shadow_size = 60;
		/ *INFO.motion |= MOV_DEF;* /
		/ *direction_check();* /
		return;
	}
	*/
	
	/* 左右移動 */
	/* 上下のチェックはしなくても上の処理で引っ掛かっているのでいいのだ */
	if( COMMAND_F || COMMAND_B ){
		
		INFO.ptr_set = 1; /* 取り合えず */
		INFO.count_a += speed;
		INFO.shadow_size = 64;
		direction_check();
		
		if( INFO.count_a<120 ){
			INFO.ptr_no = 0;
			
		} else if( INFO.count_a<240 ){
			INFO.ptr_no = 1;
			
		} else if( INFO.count_a<360 ){
			INFO.ptr_no = 2;
			
		} else if( INFO.count_a<480 ){
			INFO.ptr_no = 1;
			
		} else {
			INFO.ptr_no = 0;
			INFO.count_a = 0;
			
		}
		
		/* 移動,相手と近かったら押す */
		j = 20*speed;
		if( CommandBuff[player][0]&PAD_LEFT ){
			j *= -1;
			if( INFO.direction==-1 )	i = 1;
			else	i = 0;
		} else {
			if( INFO.direction== 1 )	i = 1;
			else	i = 0;
		}
		
		/* 自分の移動 */
		INFO.pos_x += j;
		
		/* 相手を押す */
		if( ((((YOU.pos_x-INFO.pos_x)/POS_DEC)*INFO.direction)<30)
		&& i && (YOU.pos_y/POS_DEC==ground) ){
			INFO.pos_x -= j/2;
			YOU.pos_x += j/2;
		}
		
		return 0;
	}
	
	
	
	/* 相手と近すぎたら離れる(押される) */
	/*
	if( (-24<(YOU.pos_x-INFO.pos_x)/POS_DEC)&&
		((YOU.pos_x-INFO.pos_x)/POS_DEC<24) &&
		(INFO.pos_y/POS_DEC==ground)&&(YOU.pos_y/POS_DEC>ground-40) ){
		i = 20*speed;
		dir_negation(i);
		INFO.pos_x -= i;
	}
	*/
	
	
	/* 向き替え */
	if( ((((INFO.pos_x>YOU.pos_x)&&(INFO.direction== 1)) ||
	      ((INFO.pos_x<YOU.pos_x)&&(INFO.direction==-1))))  ){
	    
		INFO.ptr_set = 1;
		INFO.ptr_no = 0;
		INFO.count_a += speed;
		
		if( 0 ){
			INFO.count_a = 0;
			INFO.motion = 1;
			
		} else if( INFO.count_a<50 ){
			/*ptr_no = 3;*/
			
		} else if( INFO.count_a<100 ){
			/*ptr_no = 3;*/
			if( INFO.pos_x>YOU.pos_x ) INFO.direction = -1;
			if( INFO.pos_x<YOU.pos_x ) INFO.direction =  1;
			
		} else {
			/*ptr_no = 3;*/
			INFO.motion = 0;
			INFO.count_a = 0;
			
		}
		return 0;
	}
	
	
	
	/* その他 … つまりニュートラル状態 */
	INFO.ptr_set = 1;
	INFO.shadow_size = 64;
	INFO.count_a += speed;
	
	if(      INFO.count_a<200  )	INFO.ptr_no = 0;
	else if( INFO.count_a<400  )	INFO.ptr_no = 1;
	else if( INFO.count_a<600 )		INFO.ptr_no = 2;
	else if( INFO.count_a<800 )		INFO.ptr_no = 1;
	else{	 INFO.count_a = 0;		INFO.ptr_no = 0; }
	
	return 0;
}




