----------------------------
my_preact = {};
enemy_preact = {};
my_preframe = {};
enemy_preframe = {};
my_allframe = 0;
enemy_allframe = 0;

for i=0,10,1 do
my_preact[i] = 0;
enemy_preact[i] = 0;
my_preframe[i] = 0;
enemy_preframe[i] = 0;
end

my_frontside = 0;
enemy_frontside = 0;
----------------------------

old_bt = 0;

RnI_B = 0;
RnI_C = 0;
B_count = 0; --ホールド専用変数
C_count = 0;

old_x = 0;
old_ex = 0;
my_xspeedEX = 0;
enemy_xspeedEX = 0;
old_m_ys = 0;
old_e_ys = 0;
m_gs = 0;
e_gs = 0;
old_obj_dis = 0;
obj_speedEX = 0;

obj_disEX = 0;
old_obj_disEX = 0;

enemy_hitarea_right = {};
enemy_hitarea_left = {};
enemy_hitarea_top = {};
enemy_hitarea_bottom = {};
for i=0,10,1 do
enemy_hitarea_right[i] = 10000;
enemy_hitarea_left[i] = 10000;
enemy_hitarea_top[i] = 10000;
enemy_hitarea_bottom[i] = 10000;
end


pre0_enemy_obj_n = 0

true_math = 0;
bio_math = 0;
graund_math = 0;
air_math = 0;

enemy_obj_act = {};
enemy_obj_x = {};
enemy_obj_y = {};
enemy_obj_hp = {};
enemy_obj_img = {};
enemy_obj_frame = {};
enemy_obj_xspeed = {};
enemy_obj_yspeed = {};
enemy_obj_id = {};
enemy_obj_attackarea_n = {};
enemy_obj_hit_n = {};

pre0_enemy_obj_act = {};
pre0_enemy_obj_x = {};
pre0_enemy_obj_y = {};
pre0_enemy_obj_hp = {};
pre0_enemy_obj_img = {};
pre0_enemy_obj_frame = {};
pre0_enemy_obj_xspeed = {};
pre0_enemy_obj_yspeed = {};
pre0_enemy_obj_id = {};
pre0_enemy_obj_attackarea_n = {};
pre0_enemy_obj_hit_n = {};

enemy_obj_attackarea_left = {};
enemy_obj_attackarea_top = {};
enemy_obj_attackarea_right = {};
enemy_obj_attackarea_bottom = {};

enemy_obj_xaccel = {};
enemy_obj_yaccel = {};

for i=0,1023,1 do
enemy_obj_act[i] = -1;
enemy_obj_x[i] = 10000;
enemy_obj_y[i] = 10000;
enemy_obj_hp[i] = -10000;
enemy_obj_img[i] = -1;
enemy_obj_frame[i] = -1;
enemy_obj_xspeed[i] = 0;
enemy_obj_yspeed[i] = 0;
enemy_obj_id[i] = -1;
enemy_obj_attackarea_n[i] = 0;
enemy_obj_hit_n[i] = 0;

pre0_enemy_obj_act[i] = -1;
pre0_enemy_obj_x[i] = 10000;
pre0_enemy_obj_y[i] = 10000;
pre0_enemy_obj_hp[i] = -10000;
pre0_enemy_obj_img[i] = -1;
pre0_enemy_obj_frame[i] = -1;
pre0_enemy_obj_xspeed[i] = 0;
pre0_enemy_obj_yspeed[i] = 0;
pre0_enemy_obj_id[i] = -1;
pre0_enemy_obj_attackarea_n[i] = 0;
pre0_enemy_obj_hit_n[i] = 0;

enemy_obj_attackarea_left[i] = 10000;
enemy_obj_attackarea_top[i] = 10000;
enemy_obj_attackarea_right[i] = 10000;
enemy_obj_attackarea_bottom[i] = 10000;

enemy_obj_xaccel[i] = 0;
enemy_obj_yaccel[i] = 0;
end

countD = 0; --飛翔用カウント
after_guard_count = 180; --ガード後のカウント
loop_count = 0; --whileループ等のループカウント

my_backside = 0;
enemy_backside = 0;

my_airEX = 0;
enemy_airEX = 0;

recovary_time = 0;
flag_kishitu = 0;

atk_count = 0;
shoot_count = 0;
datk_count = 1;

--key_resetEX関数
function key_resetEX()
	if RnI_B == 0 and RnI_C ==0 then
		key_reset();
	elseif RnI_B ==1 and RnI_C ==0 then
		key_off(ACT_UP);	key_off(ACT_DOWN);	key_off(ACT_LEFT);	key_off(ACT_RIGHT);	key_off(ACT_A);	key_off(ACT_C);	key_off(ACT_D);	key_off(ACT_AB); key_off(ACT_BC);
	elseif RnI_B ==0 and RnI_C ==1 then
		key_off(ACT_UP);	key_off(ACT_DOWN);	key_off(ACT_LEFT);	key_off(ACT_RIGHT);	key_off(ACT_A);	key_off(ACT_B);	key_off(ACT_D);	key_off(ACT_AB); key_off(ACT_BC);
	elseif RnI_B ==1 and RnI_C ==1 then
		key_off(ACT_UP);	key_off(ACT_DOWN);	key_off(ACT_LEFT);	key_off(ACT_RIGHT);	key_off(ACT_A);	key_off(ACT_D);	key_off(ACT_AB); key_off(ACT_BC);
	end
end

--スペルカード使用用のカードゲージ判定関数（コスト１には不要）
function my_spell_more(cost)
	if (my_spell>=cost or (weather==2 and my_spell>=cost-500)) then
		return true;
	else
		return false;
	end
end

--現在指定カードを持っている場合は真、そうでないなら偽
function card_check(card_ID)--連続で実行するとnillが返るらしい。
	if (get_card_id(0,0)==card_ID or get_card_id(0,1)==card_ID or get_card_id(0,2)==card_ID or get_card_id(0,3)==card_ID or get_card_id(0,4)==card_ID) then
		return true;
	else
		return false;
	end
end

--指定カードを一枚目に持ってくるだけの関数
--処理が停滞しないようにbattle_timeと剰余を利用
function card_1st(card_ID)
	if my_card~=card_ID then
		if battle_time%2==0 then
			key_on(ACT_AB);
		elseif battle_time%2==1 then
			key_off(ACT_AB);
		end
	end
end

--指定カードを一枚目に持ってきて使用する関数（空中使用可能カードに注意）
function card_use(card_ID)
	if my_card==card_ID then
		key_off(ACT_LEFT);
		key_off(ACT_RIGHT);
		key_off(ACT_UP);
		key_off(ACT_DOWN);
		key_event(ACT_BC);
	elseif my_card~=card_ID then
		if battle_time%2==0 then
			key_on(ACT_AB);
		elseif battle_time%2==1 then
			key_off(ACT_AB);
		end
	end
end

--指定範囲内で自分に向ってきているオブジェクトを認識する関数。ｙ軸未対応。妖夢対応。
function obj_coming_in(range)
	if (obj_dis<=200 and enemy_char~=5) or (obj_disEX<=200 and enemy_char==5) then
		return true;
	elseif (obj_dis<=range and enemy_char~=5 and obj_speedEX>=0) or (obj_disEX<=range and enemy_char==5 and obj_speedEX>=0) then
		return true;
	elseif (enemy_char~=5 and (obj_dis>range or obj_speedEX<0)) or (enemy_char==5 and (obj_disEX>range or obj_speedEX<0)) then
		return false;
	end
end

--nフレーム後のオブジェクトの座標を一意に返す関数：
--指定範囲内に攻撃オブジェクトの判定が、指定フレーム後に存在するか判定する関数。ｘ軸、ｙ軸対応。非常に重い。妖夢のobjバグには、obj_coming_in関数を利用する事。なお、性質上も、仕様上も２F以上からでないと利用不可。
function obj_range_in(range, ff)
	local in_of_ranges = 0
	
	for F=ff-2,ff,1 do--指定Ｆ通りの予測にはならない。小さい値程正確で、大きい値程偏差が大きい。というか、処理が間に合ってないかもしれない。10でほぼ仕様通り。30で20F内。60で30F内。
		for  i=0,enemy_obj_n-1,1 do --ループ構文により敵オブジェクトの数だけ巡回する
		
			if enemy_obj_id[i] == pre0_enemy_obj_id[i] then --敵のｎ番目のオブジェクトのIDが同一の場合、計算量を減らす事ができる：ループで繰り返すことで、前のフレームで記録したオブジェクトと同一のオブジェクトが存在するかを調べている。
						for n=0,enemy_obj_attackarea_n[i]-1,1 do --オブジェクトIDが一致したら、アタックエリアの数だけループする。
							if	x+30  +range +(my_xspeedEX*F)					>= (enemy_obj_attackarea_left[(i+1)*100+(n+1)]) 	+ (enemy_obj_xspeed[i]*enemy_dir*F)	+ (F*(F-1)*enemy_obj_xaccel[i]/2)and --ここから先が猛烈に重くなる。低スペにはつらい
								x-30  -range +(my_xspeedEX*F)					<= (enemy_obj_attackarea_right[(i+1)*100+(n+1)]) 	+  enemy_obj_xspeed[i]*enemy_dir*F	+  F*(F-1)*enemy_obj_xaccel[i]/2 and
								y-0	  -range +(my_yspeed*F+(F*((F-1)*m_gs))/2)	<= (enemy_obj_attackarea_top[(i+1)*100+(n+1)]) 		+  enemy_obj_yspeed[i]*F 			+  F*(F-1)*enemy_obj_yaccel[i]/2 and
								y+180 +range +(my_yspeed*F+(F*((F-1)*m_gs))/2) 	>= (enemy_obj_attackarea_bottom[(i+1)*100+(n+1)]) 	+  enemy_obj_yspeed[i]*F 			+  F*(F-1)*enemy_obj_yaccel[i]/2 then
									in_of_ranges = in_of_ranges + 1
							end
						end
			elseif enemy_obj_id[i] ~= pre0_enemy_obj_id[i] then --オブジェクトIDがズレた場合、i番目のオブジェクトと合致するIDを探索しなければならない。
				for ii=0,pre0_enemy_obj_n-1,1 do --前オブジェクト数分のループから合致するオブジェクトiiを探索するループ
					if enemy_obj_id[i] == pre0_enemy_obj_id[ii] then --前者のオブジェクトに対して、後者のオブジェクトが一致するもの
						for n=0,enemy_obj_attackarea_n[i]-1,1 do --アタックエリアの数だけ巡回：０（アタックエリアが１つ）でも１周はするはず
							if	x+30  +range +my_xspeedEX*F						>= (enemy_obj_attackarea_left[(i+1)*100+(n+1)]) 	+ enemy_obj_xspeed[i]*enemy_dir*F 	+ F*(F-1)*enemy_obj_xaccel[i]/2 and
								x-30  -range +my_xspeedEX*F						<= (enemy_obj_attackarea_right[(i+1)*100+(n+1)]) 	+ enemy_obj_xspeed[i]*enemy_dir*F 	+ F*(F-1)*enemy_obj_xaccel[i]/2 and
								y-0	  -range +(my_yspeed*F+(F*((F-1)*m_gs))/2)	<= (enemy_obj_attackarea_top[(i+1)*100+(n+1)]) 		+ enemy_obj_yspeed[i]*F 			+ F*(F-1)*enemy_obj_yaccel[i]/2 and
								y+180 +range +(my_yspeed*F+(F*((F-1)*m_gs))/2) 	>= (enemy_obj_attackarea_bottom[(i+1)*100+(n+1)]) 	+ enemy_obj_yspeed[i]*F				+ F*(F-1)*enemy_obj_yaccel[i]/2 then
									in_of_ranges = in_of_ranges + 1
							end
						end
					end
				end
			end
			
		end
	end
	
	if in_of_ranges>=1 then
		return true
	else
		return false
	end
	
end

function caution_state_obj(obj_act,obj_img,X,Y,F1,F2)

	true_math = 0;
	
	for i=0,enemy_obj_n-1,1 do
		if obj_act==10000 and obj_img~=10000 and enemy_obj_img[i]==obj_img then
			if 	enemy_obj_x[i]-X <= x+ 30 and 
				enemy_obj_x[i]+X >= x- 30 and
				enemy_obj_y[i]-Y <= y+180 and
				enemy_obj_y[i]+Y >= y+  0 and
				enemy_obj_frame[i] >= F1 and
				enemy_obj_frame[i] <= F2 then
					true_math = true_math + 1;
			end
		elseif obj_act~=10000 and obj_img==10000 and enemy_obj_act[i]==obj_act then
			if 	enemy_obj_x[i]-X <= x+ 30 and 
				enemy_obj_x[i]+X >= x- 30 and
				enemy_obj_y[i]-Y <= y+180 and
				enemy_obj_y[i]+Y >= y+  0 and
				enemy_obj_frame[i] >= F1 and
				enemy_obj_frame[i] <= F2 then
					true_math = true_math + 1;
			end
		elseif obj_act~=10000 and obj_img~=10000 and enemy_obj_act[i]==obj_act and enemy_obj_img[i]==obj_img then
			if 	enemy_obj_x[i]-X <= x+ 30 and 
				enemy_obj_x[i]+X >= x- 30 and
				enemy_obj_y[i]-Y <= y+180 and
				enemy_obj_y[i]+Y >= y+  0 and
				enemy_obj_frame[i] >= F1 and
				enemy_obj_frame[i] <= F2 then
					true_math = true_math + 1;
			end
		end
	end
	
	return true_math;
	
end

function atk_rapid_calc(enemy_act)
	if rapid[enemy_act] - enemy_allframe > 8+2 then
		return true
	else
		return false
	end
end

rapid = {};
for i=0,700,1 do
	rapid[i] = 0;
end

stand_neutral = 0
stand_front = 0
stand_back = 0
caution_range = 0
base_chain = 0
muteki = 0
graze_atk = 0
		
function base_states()
--霊夢
	if enemy_char==0 then
		print("Target = 霊夢")
		stand_neutral = 34;
		stand_front = 54;
		stand_back = 54;
		caution_range = 320;
		base_chain = 4;
		graze_atk = 2;
		rapid[300] = 8
		rapid[301] = 13
		rapid[302] = 16
		rapid[303] = 9
		rapid[304] = 12
		rapid[305] = 10
		rapid[306] = 10
		rapid[307] = 14
		rapid[308] = 17
		rapid[309] = 9
		rapid[311] = 0
		rapid[320] = 7
		rapid[321] = 9
		rapid[322] = 16
		rapid[323] = 0
		rapid[324] = 0
		rapid[325] = 0
		rapid[330] = 8
		rapid[331] = 0
		rapid[332] = 0
		rapid[400] = 15
		rapid[401] = 14
		rapid[402] = 14
		rapid[403] = 0
		rapid[404] = 15
		rapid[405] = 0
		rapid[406] = 14
		rapid[407] = 0
		rapid[408] = 18
		rapid[409] = 0
		rapid[410] = 25
		rapid[411] = 0
		rapid[412] = 15
		rapid[413] = 0
		rapid[414] = 18
		rapid[415] = 0
		rapid[416] = 21
		rapid[417] = 0
		rapid[418] = 12
--魔理沙
	elseif enemy_char==1 then
		print("Target = 魔理沙")
		stand_neutral = 36;
		stand_front = 52;
		stand_back = 51;
		base_chain = 4;
		muteki = 1;
		m300_rapid = 7;
--咲夜
	elseif enemy_char==2 then
		print("Target = 咲夜")
		stand_neutral = 38;
		stand_front = 44;
		stand_back = 46;
		base_chain = 4;
		graze_atk = 2;
		m300_rapid = 8;
--アリス
	elseif enemy_char==3 then
		print("Target = アリス")
		stand_neutral = 29;
		stand_front = 49;
		stand_back = 49;
		base_chain = 4;
		caution_range = 400;
		m300_rapid = 9;
--パチュリー
	elseif enemy_char==4 then
		print("Target = パチュリー")
		stand_neutral = 27;
		stand_front = 47;
		stand_back = 47;
		base_chain = 3;
		m300_rapid = 9;
--妖夢
	elseif enemy_char==5 then
		print("Target = 妖夢")
		stand_neutral = 25;
		stand_front = 57;
		stand_back = 57;
		base_chain = 5;
		muteki = 1;
		m300_rapid = 7;
--レミリア
	elseif enemy_char==6 then
		print("Target = レミリア")
		stand_neutral = 29;
		stand_front = 35;
		stand_back = 35;
		base_chain = 4;
		muteki = 1;
		graze_atk = 2;
		m300_rapid = 7;
--幽々子
	elseif enemy_char==7 then
		print("Target = 幽々子")
		stand_neutral = 19;
		stand_front = 63;
		stand_back = 63;
		base_chain = 3;
		graze_atk = 2;
		m300_rapid = 10;
--紫
	elseif enemy_char==8 then
		print("Target = 紫")
		stand_neutral = 58;
		stand_front = 76;
		stand_back = 76;
		base_chain = 4;
		caution_range = 320;
		graze_atk = 2;
		m300_rapid = 9;
--萃香
	elseif enemy_char==9 then
		print("Target = 萃香")
		stand_neutral = 35;
		stand_front = 47;
		stand_back = 47;
		base_chain = 4;
		graze_atk = 2;
		m300_rapid = 9;
--文
	elseif enemy_char==11 then
		print("Target = 文")
		stand_neutral = 36;
		stand_front = 46;
		stand_back = 46;
		base_chain = 4;
		graze_atk = 2;
		m300_rapid = 7;
--うどんげ
	elseif enemy_char==10 then
		print("Target = うどんげ")
		stand_neutral = 43;
		stand_front = 45;
		stand_back = 58;
		base_chain = 4;
		graze_atk = 1;
		m300_rapid = 7;
--小町
	elseif enemy_char==12 then
		print("Target = 小町")
		stand_neutral = 47;
		stand_front = 54;
		stand_back = 54;
		base_chain = 4;
		caution_range = 350;
		graze_atk = 1;
		m300_rapid = 9;
--衣玖
	elseif enemy_char==13 then
		print("Target = 衣玖")
		stand_neutral = 39;
		stand_front = 88;
		stand_back = 88;
		base_chain = 4;
		caution_range = 350;
		m300_rapid = 8;
--天子
	elseif enemy_char==14 then
		print("Target = 天子")
		stand_neutral = 31;
		stand_front = 42;
		stand_back = 42;
		base_chain = 3;
		graze_atk = 2;
		m300_rapid = 9;
--早苗
	elseif enemy_char==15 then
		print("Target = 早苗")
		stand_neutral = 25;
		stand_front = 53;
		stand_back = 58;
		base_chain = 4;
		graze_atk = 2;
		m300_rapid = 7;
--チルノ
	elseif enemy_char==16 then
		print("Target = チルノ")
		stand_neutral = 31;
		stand_front = 54;
		stand_back = 54;
		base_chain = 4;
		m300_rapid = 6;
--美鈴
	elseif enemy_char==17 then
		print("Target = 美鈴")
		stand_neutral = 26;
		stand_front = 44;
		stand_back = 44;
		base_chain = 4;
		graze_atk = 2;
		m300_rapid = 6;
--空
	elseif enemy_char==18 then
		print("Target = 空")
		stand_neutral = 20;
		stand_front = 55;
		stand_back = 55;
		base_chain = 4;
		graze_atk = 1;
		m300_rapid = 7;
--諏訪子
	elseif enemy_char==19 then
		print("Target = 諏訪子")
		stand_neutral = 29;
		stand_front = 81;
		stand_back = 81;
		base_chain = 4;
		m300_rapid = 7;
	end
end

		
function calculation()
while true do

	if enemy_obj_n>=1 then
		--obj各個変数化
		for i=0,enemy_obj_n-1,1 do
			enemy_obj_act[i],enemy_obj_x[i],enemy_obj_y[i],enemy_obj_hp[i],enemy_obj_img[i],enemy_obj_frame[i],enemy_obj_xspeed[i],enemy_obj_yspeed[i],enemy_obj_id[i],enemy_obj_attackarea_n[i],enemy_obj_hit_n[i] = get_obj_data(1,i);
		end
		--obj攻撃判範囲
		for i=0,enemy_obj_n-1,1 do
			for n=0,enemy_obj_attackarea_n[i]-1,1 do
				enemy_obj_attackarea_left[(i+1)*100+(n+1)],enemy_obj_attackarea_top[(i+1)*100+(n+1)],enemy_obj_attackarea_right[(i+1)*100+(n+1)],enemy_obj_attackarea_bottom[(i+1)*100+(n+1)] = get_obj_attackarea(1,i,n);
			end
		end
		--obj加速度
		if battle_time-old_bt>=1 then
			for i=0,enemy_obj_n-1,1 do
				if enemy_obj_id[i] == pre0_enemy_obj_id[i] and enemy_obj_attackarea_n[i]>=1 then
				
							enemy_obj_xaccel[i] 	= math.floor(((enemy_obj_xspeed[i]-pre0_enemy_obj_xspeed[i])/(battle_time-old_bt))*1000)/1000
							enemy_obj_yaccel[i] 	= math.floor(((enemy_obj_yspeed[i]-pre0_enemy_obj_yspeed[i])/(battle_time-old_bt))*1000)/1000
							
				elseif enemy_obj_id[i] ~= pre0_enemy_obj_id[i] then
				
					for ii=0,pre0_enemy_obj_n-1,1 do
						if enemy_obj_id[i] == pre0_enemy_obj_id[ii] and enemy_obj_attackarea_n[i]>=1 then
						
							enemy_obj_xaccel[i] 	= math.floor(((enemy_obj_xspeed[i]-pre0_enemy_obj_xspeed[ii])/(battle_time-old_bt))*1000)/1000
							enemy_obj_yaccel[i] 	= math.floor(((enemy_obj_yspeed[i]-pre0_enemy_obj_yspeed[ii])/(battle_time-old_bt))*1000)/1000
							
						end
					end
					
				end
			end
		end
	end

--▼どれくらい地上or空中にいたのかをカウント▼
	if ey==0 then
		air_math = 0;
	elseif ey>0 then
		air_math = air_math+1;
	end
	if ey>0 then
		graund_math = 0;
	elseif ey==0 then
		graund_math = graund_math+1;
	end
	
--▼ガードするごとに初期値にリセットされる変数▼
	if  (stage_number==10 or 
		(my_char== 0 and bgm_number==40) or
		(my_char== 1 and bgm_number==41) or
		(my_char== 2 and bgm_number==12) or
		(my_char== 3 and bgm_number==42) or
		(my_char== 4 and bgm_number==15) or
		(my_char== 5 and bgm_number==14) or
		(my_char== 6 and bgm_number==17) or
		(my_char== 7 and bgm_number==16) or
		(my_char== 8 and bgm_number==18) or
		(my_char== 9 and bgm_number==19) or
		(my_char==10 and bgm_number==20) or
		(my_char==11 and bgm_number==21) or
		(my_char==12 and bgm_number==22) or
		(my_char==13 and bgm_number== 4) or
		(my_char==14 and bgm_number== 5) or
		(my_char==15 and bgm_number==30) or
		(my_char==16 and bgm_number==31) or
		(my_char==17 and bgm_number==32) or
		(my_char==18 and bgm_number==33) or
		(my_char==19 and bgm_number==34)
		) then
		after_guard_count = 1
	elseif ((my_act>=50 and my_act<=89) or (my_act>=143 and my_act<=166)) and my_frame<=1 then
		after_guard_count = 60;
	elseif after_guard_count>=2 then
		after_guard_count = after_guard_count-1
	elseif after_guard_count<=1 then
		after_guard_count = 1
	end
	
--▼ガード用バオイリズムの制御変数▼
	if bio_math<0 then
		bio_math = 0
	elseif bio_math>10000 then
		bio_math = 10000
	elseif dis<=20 then
		bio_math = 10000
		
	elseif enemy_act>=306 and enemy_act<=309 and air_math>=30 and y<=20 and enemy_allframe==1 and my_hitstop==0  then
		bio_math = 0
		
	elseif my_act==97 then
		bio_math = bio_math+math.random(500)
		
	elseif enemy_act>=300 and enemy_preact[1]>=300 and enemy_preact[1]==enemy_act and enemy_frame<=0 and my_hitstop==0  then
		bio_math = bio_math-4000
	elseif enemy_act>=0 and enemy_preact[1]>=300 and enemy_preact[1]~=enemy_act and enemy_frame<=0 and my_hitstop==0  then
		bio_math = bio_math+8000
		
	elseif enemy_act>=50 and enemy_act<=145 and enemy_frame<=0 and enemy_hitstop==0 then
		bio_math = bio_math+1500
	elseif enemy_act>=150 and enemy_act<=158 and enemy_frame<=0 and enemy_hitstop==0 then
		bio_math = bio_math+1000
	elseif enemy_act>=159 and enemy_act<=166 and enemy_frame<=0 and enemy_hitstop==0 then
		bio_math = bio_math+500
		
	elseif my_act>=50 and my_act<=145 and my_frame+1==1 and my_hitstop==0 then
		bio_math = bio_math-500
	elseif my_act>=150 and my_act<=158 and my_frame+1==1 and my_hitstop==0 then
		bio_math = bio_math-1000
	elseif my_act>=159 and my_act<=166 and my_frame+1==1 and my_hitstop==0 then
		bio_math = bio_math-1500
		
	elseif bio_math<10000 then
		bio_math = bio_math+math.random(64)
	end
	
--▼対妖夢用obj_dis▼
	if enemy_char==5 and enemy_obj_n<=5 then
		obj_disEX = 10000;
	elseif enemy_char==5 and enemy_obj_n>=6 then
		obj_disEX = obj_dis;
	end
	
--▼過去のモーション、フレームの格納▼
--東方緋想天　AI関連スレッド1 >>80より

--直前actと異なっていたら、もしくは同じact番号でもframeが巻き戻っていたら記録する(自分)
	if not(my_preact[0] == my_act and my_preframe[0] <= my_frame) then
		for i=5,1,-1 do
			my_preact[i] = my_preact[i-1];
			my_preframe[i] = my_preframe[i-1];
		end
	end
--直前actと異なっていたら、もしくは同じact番号でもframeが巻き戻っていたら記録する(相手)
	if not(enemy_preact[0] == enemy_act and enemy_preframe[0] <= enemy_frame) then
		for i=5,1,-1 do
			enemy_preact[i] = enemy_preact[i-1];
			enemy_preframe[i] = enemy_preframe[i-1];
		end
	end
--フレーム総数の記録(自分)
	--[[if		my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] and my_act == my_preact[6] and my_act == my_preact[7] and my_act == my_preact[8] and my_act == my_preact[9] and my_act == my_preact[10] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + my_preframe[6] + my_preframe[7] + my_preframe[8] + my_preframe[9] + my_preframe[10] + 10 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] and my_act == my_preact[6] and my_act == my_preact[7] and my_act == my_preact[8] and my_act == my_preact[9] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + my_preframe[6] + my_preframe[7] + my_preframe[8] + my_preframe[9] + 9 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] and my_act == my_preact[6] and my_act == my_preact[7] and my_act == my_preact[8] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + my_preframe[6] + my_preframe[7] + my_preframe[8] + 8 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] and my_act == my_preact[6] and my_act == my_preact[7] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + my_preframe[6] + my_preframe[7] + 7 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] and my_act == my_preact[6] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + my_preframe[6] + 6 + 1 ;
	else--]]if my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] and my_act == my_preact[5] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + my_preframe[5] + 5 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] and my_act == my_preact[4] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + my_preframe[4] + 4 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] and my_act == my_preact[3] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + my_preframe[3] + 3 + 1 ;
	elseif my_act == my_preact[1] and my_act == my_preact[2] then
		my_allframe = my_frame + my_preframe[1] + my_preframe[2] + 2 + 1 ;
	elseif my_act == my_preact[1] then
		my_allframe = my_frame + my_preframe[1] + 1 + 1 ;
	else
		my_allframe = my_frame + 1 ;
	end
--フレーム総数の記録(相手)
	--[[if		enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] and enemy_act == enemy_preact[6] and enemy_act == enemy_preact[7] and enemy_act == enemy_preact[8] and enemy_act == enemy_preact[9] and enemy_act == enemy_preact[10] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + enemy_preframe[6] + enemy_preframe[7] + enemy_preframe[8] + enemy_preframe[9] + enemy_preframe[10] + 10 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] and enemy_act == enemy_preact[6] and enemy_act == enemy_preact[7] and enemy_act == enemy_preact[8] and enemy_act == enemy_preact[9] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + enemy_preframe[6] + enemy_preframe[7] + enemy_preframe[8] + enemy_preframe[9] + 9 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] and enemy_act == enemy_preact[6] and enemy_act == enemy_preact[7] and enemy_act == enemy_preact[8] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + enemy_preframe[6] + enemy_preframe[7] + enemy_preframe[8] + 8 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] and enemy_act == enemy_preact[6] and enemy_act == enemy_preact[7] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + enemy_preframe[6] + enemy_preframe[7] + 7 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] and enemy_act == enemy_preact[6] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + enemy_preframe[6] + 6 + 1 ;
	else--]]if enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] and enemy_act == enemy_preact[5] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + enemy_preframe[5] + 5 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] and enemy_act == enemy_preact[4] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + enemy_preframe[4] + 4 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] and enemy_act == enemy_preact[3] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + enemy_preframe[3] + 3 + 1 ;
	elseif enemy_act == enemy_preact[1] and enemy_act == enemy_preact[2] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + enemy_preframe[2] + 2 + 1 ;
	elseif enemy_act == enemy_preact[1] then
		enemy_allframe = enemy_frame + enemy_preframe[1] + 1 + 1 ;
	else
		enemy_allframe = enemy_frame + 1 ;
	end
--▼敵食らい判定の取得▼
	for i=0,enemy_hitarea_n,1 do		enemy_hitarea_left[i],enemy_hitarea_top[i],enemy_hitarea_right[i],enemy_hitarea_bottom[i] = get_hitarea(1,i);	end
	for i=0,enemy_hitarea_n,1 do		if enemy_hitarea_left[i] == nil then			enemy_hitarea_left[i] = 10000;		end	end
	for i=0,enemy_hitarea_n,1 do		if enemy_hitarea_top[i] == nil then			enemy_hitarea_top[i] = 10000;		end	end
	for i=0,enemy_hitarea_n,1 do		if enemy_hitarea_right[i] == nil then			enemy_hitarea_right[i] = 10000;		end	end
	for i=0,enemy_hitarea_n,1 do		if enemy_hitarea_bottom[i] == nil then			enemy_hitarea_bottom[i] = 10000;		end	end
--▼絶対座標に対する速度と座標より算出した速度▼
	if battle_time-old_bt==1 then
	
		if x<=40 or x>=1240 then
			my_xspeedEX = 0
		else
			if my_hitstop==0 then
				my_xspeedEX = (x-old_x)*my_dir;
			else
				my_xspeedEX = 0
			end
		end
		
		if ex<=40 or ex>=1240 then
			enemy_xspeedEX = 0
		else
			if enemy_hitstop==0 then
				enemy_xspeedEX = (ex-old_ex)*enemy_dir;
			else
				enemy_xspeedEX = 0
			end
		end
		
	elseif battle_time-old_bt>=2 then
	
		if x<=40 or x>=1240 then
			my_xspeedEX = 0
		else
			if my_hitstop==0 then
				my_xspeedEX = (x-old_x)/(battle_time-old_bt)*my_dir;
			else
				my_xspeedEX = 0
			end
		end
		
		if ex<=40 or ex>=1240 then
			enemy_xspeedEX = 0
		else
			if enemy_hitstop==0 then
				enemy_xspeedEX = (ex-old_ex)/(battle_time-old_bt)*enemy_dir;
			else
				enemy_xspeedEX = 0
			end
		end
		
	end
	
--▼落下加速度の演算▼
	if battle_time-old_bt==1 then --更新速度の計測
		if y==0 then
			old_m_ys = 0;
			m_gs = 0;
		elseif y>0 then
			m_gs = my_yspeed - old_m_ys; --瞬間の落下加速度の計測
		end
		if ey==0 then
			old_e_ys = 0;
			e_gs = 0;
		elseif ey>0 then
			e_gs = enemy_yspeed - old_e_ys;
		end
	end
--▼射撃オブジェの速度演算。正の時、接近。負ならば離脱と認識できる▼
	if obj_dis==10000 then
		old_obj_dis = 0
		obj_speedEX = 0
	elseif obj_dis<10000 then
		obj_speedEX = old_obj_dis - obj_dis
	end
	
--▼端までの距離計算。0〜1200▼
	if my_dir == 1 then
		my_frontside = 1240 - x
	else
		my_frontside = x - 40
	end

	if enemy_dir == 1 then
		enemy_frontside = 1240 - ex
	else
		enemy_frontside = ex - 40
	end
----
	if my_dir == 1 then
		my_backside = x - 40
	else
		my_backside = 1240 - x
	end

	if enemy_dir == 1 then
		enemy_backside = ex - 40
	else
		enemy_backside = 1240 - ex
	end
	
--▼飛翔の残り回数の演算▼
	if weather~=10 then
		if my_air==0 then
			my_airEX = 2
		elseif my_air==1 then
			my_airEX = 1
		elseif my_air>=2 then
			my_airEX = 0
		end
	else
		if my_air==0 then
			my_airEX = 3
		elseif my_air==1 then
			my_airEX = 2
		elseif my_air==2 then
			my_airEX = 1
		elseif my_air>=3 then
			my_airEX = 0
		end
	end
	if weather~=10 then
		if enemy_air==0 then
			enemy_airEX = 2
		elseif enemy_air==1 then
			enemy_airEX = 1
		elseif enemy_air>=2 then
			enemy_airEX = 0
		end
	else
		if enemy_air==0 then
			enemy_airEX = 3
		elseif enemy_air==1 then
			enemy_airEX = 2
		elseif enemy_air==2 then
			enemy_airEX = 1
		elseif enemy_air>=3 then
			enemy_airEX = 0
		end
	end
	
--▼気質フラグの演算▼
	--「緋想の剣」発現中のフラグ維持
	if my_act==691 and flag_kishitu==2 then 
		flag_kishitu = 2
		
	--「緋想の剣」発現後のフラグ維持
	elseif weather == 6 and flag_kishitu==2 then 
		flag_kishitu = 2
	elseif weather == 7 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather ==13 and flag_kishitu==2 then
		flag_kishitu = 2
		
	elseif weather2== 5 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather2== 6 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather2== 8 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather2==12 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather2==18 and flag_kishitu==2 then
		flag_kishitu = 2
	elseif weather2==21 and flag_kishitu==2 then
		flag_kishitu = 2
		
	--「緋想の剣」フラグＯＮと維持
	elseif weather == 6 and flag_kishitu<=1 and enemy_hp<=6000 and my_hp>enemy_hp+2000 then 
		flag_kishitu = 1
	elseif weather == 7 and flag_kishitu<=1 then
		flag_kishitu = 1
	elseif weather ==13 and flag_kishitu<=1 then
		flag_kishitu = 1
		
	elseif weather2== 5 and weather_time<=750 and flag_kishitu<=1 and enemy_hp<=6000 and my_hp>enemy_hp+2000 then
		flag_kishitu = 1
	elseif weather2== 6 and weather_time<=750 and flag_kishitu<=1 then
		flag_kishitu = 1
	elseif weather2== 8 and weather_time<=750 and flag_kishitu<=1 and my_rmax<=600 then
		flag_kishitu = 1
	elseif weather2==12 and weather_time<=750 and flag_kishitu<=1 then
		flag_kishitu = 1
	elseif weather2==18 and weather_time<=750 and flag_kishitu<=1 then
		flag_kishitu = 1
	elseif weather2==21 and weather_time<=750 and flag_kishitu<=1 and math.random(180)==1 then
		flag_kishitu = 1
		
	--指定条件外になった場合、フラグＯＦＦ
	else
		flag_kishitu = 0
	end
		
--魔理沙ＤＡ用の行動決定用変数
	if my_act==305 and my_allframe>=13 and not(enemy_act>=200 and enemy_act<=226) and enemy_allframe==1 and (enemy_preact[1]==152 or enemy_preact[1]==156) then
		shoot_count = shoot_count + 1
	elseif my_act==305 and my_allframe>=13 and (enemy_act>=200 and enemy_act<=226) and enemy_allframe==1 and (enemy_preact[1]==152 or enemy_preact[1]==156) then
		atk_count = atk_count + 1
		
	elseif ((my_act>=505 and my_act<=506)or(my_act>=560 and my_act<=561)) and (my_preact[1]==305 or my_preact[2]==305 or my_preact[3]==305) and	my_allframe==30 and (enemy_act>=143 and enemy_act<=166) then
		shoot_count = shoot_count + 1
	elseif ((my_act>=505 and my_act<=506)or(my_act>=560 and my_act<=561)) and (my_preact[1]==305 or my_preact[2]==305 or my_preact[3]==305) and (enemy_act>=200 and enemy_act<=226) and enemy_allframe==1 and (enemy_preact[0]==152 or enemy_preact[0]==156) then
		atk_count = atk_count + 1
		
	--elseif ((my_act>=500 and my_act<=501)or(my_act>=520 and my_act<=522)) and (my_preact[1]==305 or my_preact[2]==305 or my_preact[3]==305) and	my_hitstop==1 and (enemy_act>=143 and enemy_act<=166) then
	--	atk_count = atk_count - 1
	--	shoot_count = shoot_count + 1
	--elseif ((my_act>=500 and my_act<=501)or(my_act>=520 and my_act<=522)) and (my_preact[1]==305 or my_preact[2]==305 or my_preact[3]==305) and	my_hitstop==1 and (enemy_act>=50 and enemy_act<=89) then
	--	atk_count = atk_count - 1
	--	shoot_count = shoot_count + 1
		
	elseif ((my_act>=500 and my_act<=501)or(my_act>=520 and my_act<=522)) and (my_preact[1]==305 or my_preact[2]==305 or my_preact[3]==305) and my_allframe==1 then
		atk_count = atk_count - 1
		shoot_count = shoot_count + 1
		
	elseif my_act==305 and enemy_act>=143 and enemy_act<=166 and my_hitstop==1 then 
		datk_count = datk_count + 1
	elseif atk_count<0 then
		atk_count = 0
	elseif shoot_count<0 then
		shoot_count = 0
	end
----

	--print(battle_time-old_bt,after_guard_count,bio_math);
	--if battle_time%10==1 then
	--	print(battle_time-old_bt,atk_count,shoot_count," ",datk_count);
	--end
	
old_bt = battle_time;
old_x = x;
old_ex = ex;
old_m_ys = my_yspeed;
old_e_ys = enemy_yspeed;
old_obj_dis = obj_dis;

my_preact[0] = my_act;
my_preframe[0] = my_frame;
enemy_preact[0] = enemy_act;
enemy_preframe[0] = enemy_frame;
----
----pre_obj変数
for i=0,enemy_obj_n-1,1 do
	pre0_enemy_obj_act[i] 			= enemy_obj_act[i]
	pre0_enemy_obj_x[i] 			= enemy_obj_x[i]
	pre0_enemy_obj_y[i] 			= enemy_obj_y[i]
	pre0_enemy_obj_hp[i] 			= enemy_obj_hp[i]
	pre0_enemy_obj_img[i] 			= enemy_obj_img[i]
	pre0_enemy_obj_frame[i] 		= enemy_obj_frame[i]
	pre0_enemy_obj_xspeed[i] 		= enemy_obj_xspeed[i]
	pre0_enemy_obj_yspeed[i] 		= enemy_obj_yspeed[i]
	pre0_enemy_obj_id[i] 			= enemy_obj_id[i]
	pre0_enemy_obj_attackarea_n[i] 	= enemy_obj_attackarea_n[i]
	pre0_enemy_obj_hit_n[i] 		= enemy_obj_hit_n[i]
end

for i=0,enemy_obj_n-1,1 do
	pre0_enemy_obj_attackarea_n[i] = enemy_obj_attackarea_n[i]
end

pre0_enemy_obj_n = enemy_obj_n;
----
		

yield();
end
end