----##### th105_ai_lib_20090105SetInput̑(ǉύX_͍ŉ) #####
require("WaitEx.txt")			--damaged , waitEx , waitEx2 , waitTachi , waitMotion

--SetInput		ϔ




--@\Fcommandŗ^ꂽɃR}h͂
--SetInput=function( command [, exception [, motion [, ...] ] ] )
--
--		R}h͈͒exceptionŗ^ꂽ֐'...'^ČĂяoA߂lȔꍇ̓L[ZbgăR}h͂𒆒f܂
--		motionɃ[Vl^ꍇAR}h͊L[Ԃ̂܂܂őҋ@Aw肵[VɂȂI܂
--		(莞Ԍo߂Ẵ[VɂȂȂꍇAL[ZbgėԂɂȂ̂҂܂)
--		motion"."^ꍇAR}h͊ɑI܂
--		exeptionmotion͏Ԃt̕RłAϑOƂ̌݊lĂȊɂĂ݂܂
--
--gp
--	@F	SetInput("236B");
--	AF	SetInput("236B",nil,500);
--	BF	SetInput("236B",nil,".");
--	CF	SetInput("252BH5(50)252CH5(50)");
--	DF	SetInput("252BH5(50)252CH5(50)",nil,0);
--	EF	SetInput("2A(8)A(8)A(8)6A(13)",get_fflags(TAG_ENEMY,8));
--	FF	SetInput("252BH5(50)252CH5(50)4AE5(55)b2A5(55)cx4A5");
--	GF	waitTime=8;	SetInput("2A("..waitTime..")6A");
--	HF	SetInput("252BH5",nil,0);	--22+B̃[VdɎԂ邽߁A댯B"252B5(20)"ƂׂB
--
--(gp)
--	@ccXL236+B͂܂B͌̓L[ZbgāA[VɂȂ܂őҋ@܂B
--	AccXL236+B͂܂B͌̓L[Ԃ̂܂܂ŁA[Vl500ɂȂ܂őҋ@܂B
--	BccXL236+B͂܂B͌̓L[Ԃ̂܂܂őI܂B
--	CccXL22+B(z[h),22+C(z[h)Aœ͂܂B͌̓L[ZbĝŁAz[h͉܂B
--	DccXL22+B(z[h),22+C(z[h)Aœ͂܂B͌̓L[Ԃ̂܂܂Ȃ̂ŁAz[h͌p܂B
--	Ecc(2A)*36A̘Ag͂܂BAgrő肪󒆂ɂ炻̎_ŃL[Zbgē͂𒆒f܂B
--	Fccz[hgĕ̃{^𓯎ɑ삵Ă݂B
--	GccSetInput("2A(8)6A");	ƓB'..'ŘAł邵Aϐ̐lgƂł܂B
--	HccoJ


--################################################# R}h͋K(ϑOƂقړl) #################################################
--##<<R}h͂Ɏg镶́Aȉ̕Cӂɕׂ̂ł>>
--##
--##Eo[{ "1","2","3","4","5","6","7","8","9" }
--##	̕ɑΉփo[͂܂B
--##	͑OɁuyieldSkey_offvs܂B
--##	͎͌IɃz[h܂Bz[h͎̃o[܂ő܂B
--##	o[j[gKvȂƂ"5"Ȃ΂Ȃ܂B
--##
--##E{^{ "A","B","C","D","E","F" }
--##	̕ɑΉ{^͂܂("E"ACT_AB,"F"ACT_BCɑΉ)B
--##	O̕"H"łȂA͌Ɂuz[hłȂS{^key_resetyieldvs܂B
--##
--##Ez[h{ "H" }
--##	Õo[ɑΉ{^z[h܂B
--##	z[h͎(Ή)z[h܂ő܂B
--##
--##Ez[h{ "a","b","c","d","e","f" }
--##	Ή{^̃z[h܂B
--##	͌Ɂuyieldvs܂B
--##
--##Eҋ@{ "("..n..")" }	ccn͔CӐ
--##	n()ŊƑҋ@ɂȂ܂B
--##	L[Ԃ̂܂܂nt[ҋ@܂B
--##	Ⴆ"(26)"Ƃ26t[ҋ@܂B
--##
--##EŒҋ@{ "_","v","x" }
--##	ꂼ"(1)","(5)","(10)"Ɠ܂B
--##
--##
--##
--##
--##ϑOƂ̍
--##	ϑO͈̃{^z[hłÃ{^𓯎ɉԂɂł܂Bό͕̃{^ɑΉĂ܂B
--##	ϑOACT_BCɂĂ̈ꕔ(z[hȂ)ɑΉĂ܂Bό͑̃{^ƓɈĂ܂B
--##	
--######################################################################################################################################





----#### ֐{ ####
--gpJX^}CY֐FwaitEx2(), waitTachi() , waitMotion()
--gp萔FL[FACT_UP`ACT_BC
function SetInput( command , exception , motion , ... )
	local counter = 1	--݉Ԗڂ̕Ă邩
	local oldInput = ""	--rs߁AnilȊȌlݒ肷
	local waitProc		--waitt[w蕶쐬B쐬Ȃtrue
	local hold_btn={}	--e{^̃z[h
	
	--ŗ^ꂽR}h1ɂē͏s
	for input in string.gmatch( command, ".") do
	
	--O̒lɑ΂鏈
		--OA`F̏ꍇ
		if oldInput >= "A" and oldInput <= "F" then
			--݂̒l"H"ȂAO̓͂key_offz[h()B
			if input == "H" then
				--Vz[h{^ǉ
				hold_btn[oldInput]=true;
			
			--݂̒l"H"ȊOȂAA`F̌yieldkey_offyield͂ށB("6C"͓łB"AxA"x̑OA)
			else
				--1t2t̂قAL[(R}hs)̊mႢ
				if not waitEx2(2, exception, ...) then
					return false;
				end
				--A`F̂z[hłȂ̂key_offB
				if not hold_btn.A then	key_off( ACT_A );	end
				if not hold_btn.B then	key_off( ACT_B );	end
				if not hold_btn.C then	key_off( ACT_C );	end
				if not hold_btn.D then	key_off( ACT_D );	end
				if not hold_btn.E then	key_off( ACT_AB );	end	--E
				if not hold_btn.F then	key_off( ACT_BC );	end	--F
				--݂̒lɊւ炸ȂOyield
				--1t2t̂قAL[(R}hs)̊mႢ
				if not waitEx2(2, exception, ...) then
					return false;
				end
			end
		
		--Oa`f̏ꍇ
		elseif oldInput >= "a" and oldInput <= "f" then
			--z[hԂ폜
			hold_btn[oldInput]=false;
			--݂̒lɊւ炸ȂOyield
			if not waitEx2(1, exception, ...) then
				return false;
			end
		end
		
	--݂̒lɑ΂鏈
		--waitt[wp쐬̏ꍇ
		if waitProc then
			if input >= "0" and input <= "9" then
				--"0"`"9"waitt[wp쐬
				waitString = waitString .. input
			elseif input == ")" then
				--ʂň͂܂ꂽ𐔒lƂwait
				if not waitEx2(tonumber(waitString), exception, ...) then
					return false;
				end
				waitProc = false;
			end
		
		--LȊȌꍇ
		--(ʏ̏ꍇ)
		else
			--1`9̏ꍇ
			--1`9̑Okey_offyield͂ށB("236C"łB)
			if input >= "1" and input <= "9" then
				--1`9̑Oyield(1ڂyieldȂ)
				if counter > 1 then
					--1t2t̂قAL[(R}hs)̊mႢ
					if not waitEx2(2, exception, ...) then
						return false;
					end
				end
				--1`9̑OɑSkey_off
				key_off( ACT_UP );
				key_off( ACT_DOWN );
				key_off( ACT_LEFT );
				key_off( ACT_RIGHT );
				--key_off( ACT_DLEFT );
				--key_off( ACT_DRIGHT );
				--key_off( ACT_ULEFT );
				--key_off( ACT_URIGHT );
			end
			
			--"1"`"9", "A`E"Ȃǂ̕ɃL[͂s
			if input == "1" then
				key_on( d_back )
			elseif input == "2" then
				key_on( ACT_DOWN )
			elseif input == "3" then
				key_on( d_front )
			elseif input == "4" then
				key_on( back )
			elseif input == "5" then
				--o[j[g(ʓr"1"`"9"ʏɂď)
			elseif input == "6" then
				key_on( front )
			elseif input == "7" then
				key_on( u_back )
			elseif input == "8" then
				key_on( ACT_UP )
			elseif input == "9" then
				key_on( u_front )
			--{^
			elseif input == "A" then
				key_on( ACT_A )
			elseif input == "B" then
				key_on( ACT_B )
			elseif input == "C" then
				key_on( ACT_C )
			elseif input == "D" then
				key_on( ACT_D )
			elseif input == "E" then
				key_on( ACT_AB )
			elseif input == "F" then
				key_on( ACT_BC )
			elseif input == "H" then
				--z[h(ʓr)
			--z[h()
			elseif input == "a" then
				key_off( ACT_A )
				hold_btn.A=false;
			elseif input == "b" then
				key_off( ACT_B )
				hold_btn.B=false;
			elseif input == "c" then
				key_off( ACT_C )
				hold_btn.C=false;
			elseif input == "d" then
				key_off( ACT_D )
				hold_btn.D=false;
			elseif input == "e" then
				key_off( ACT_AB )
				hold_btn.E=false;
			elseif input == "f" then
				key_off( ACT_BC )
				hold_btn.F=false;
			--yield
			elseif input == "(" then
				waitProc = true
				waitString = ""	--
			elseif input == "_" then
				if not waitEx2(1, exception, ...) then
					return false;
				end
			elseif input == "v" then
				if not waitEx2(5, exception, ...) then
					return false;
				end
			elseif input == "x" then
				if not waitEx2(10, exception, ...) then
					return false;
				end
			end
		end
		
		--1O̓̓R}h̒lۑ
		oldInput = input
		--Ԗڂ̕Ă邩̕ϐJEgAbv
		counter = counter + 1
	end
	
--loop
	
	--Ō̃L[͂𐬗邽yield
	--1t2t̂قAL[iR}hsj̊mႢ
	if not waitEx2(2, exception, ...) then
		return false;
	end

--[[
	--L[{^
	--Fz[h()IłȂB΍FϕSetInputg킸AϒO܂ł̓͂ɂAς͕ʓrLq
	key_reset()
	--yieldBFŌCƍőł͂Ȃ(1t])Bő~Ȃʓr֐đΏ
	if not waitEx2(1, exception, ...) then
		return false;
	end
--]]
----L[ZbgwaitTachi()ɔCāAł͎sȂ悤ɂccL[Ԃ̂܂܂ŏIł

	--w肵[VɂȂ܂ő҂(w肪ȂΗ)
	--ɗZʂ𗘂̂ŁAȊɂĂ݂
	--waitTachi()KvȂ΂̂ƂɂΗǂAƂƂ
	return motion==nil and waitTachi() or motion=="." and true or waitMotion(motion);
end

----#### fin...֐{ ####





----#### ǉύX_ ####
----E֐exceptionɔCӂ̈n悤ɕύX
----E߂ltrue()false(f)ɕύX
----Eo߃t[L^elapsedFrame폜ccexception͉̈ψ'...'Ƃ
----E֐exception̖߂lL^excCode폜ccf̔exception(...)̐^UŒڔ肷
----EԂɌ炸Dȃ[VŏIł悤ɕύX
----EL[Ԃ̂܂܂ŏIł悤ɕύX
----Esɔ_炷ɒf悤ύX
----EACT_DOWNLEFTȂǂACT_DLEFTȂǂɕύX(gp)
