-----------------------------------------------------------------------------------------------------------------------
-- 試合状況判定関連
-----------------------------------------------------------------------------------------------------------------------
--ガン攻めAI
function offensiveSituation(target)
	
	if (not isControllableSituation(target))
	then
		return false;
	end

	-- 追い討ちは別口で。
	local targetEnemy = getReverseTarget(target);
	if (not isControllableSituation(targetEnemy))
	then
		return false;
	end

	local offensive = false;

	-- 過去の履歴で全般的に見て前に出てるか
	local current = tracer[target]:current();
	local history = nil;
	for i = 5, 0, -1
	do
		history = tracer[target]:history(i);
		if (history ~= nil)
		then
			break;
		end
	end

	local margin_x = current:getParameter(CaptureInfo_x) - history:getParameter(CaptureInfo_x);
	if (current:getParameter(CaptureInfo_my_dir == 1))
	then
		offensive = (margin_x >= 0);
	else
		offensive = (margin_x <= 0);
	end

	if (current:getParameter(CaptureInfo_dis_x) >= 600)
	then
		offensive = true;
	end

	--return	offensive and (not katameSituation(target));
	return	(not katameSituation(target));
end

-- 端攻め、固め状況
function katameSituation(target)
	if (not isControllableSituation(target))
	then
		return false;
	end

	local targetEnemy = getReverseTarget(target);
	--print(target, targetEnemy, getTargetRelativeX(target),getTargetRelativeX(targetEnemy),dis_x);
	return  ((getTargetRelativeX(targetEnemy) >= 450)
				and (getTargetRelativeX(target) >= 200)
				and (getTargetRelativeX(target) < getTargetRelativeX(targetEnemy))
				and (dis_x <= 400));
end

-- チキンAI
function defensiveSituation(target)
	if (not isControllableSituation(target))
	then
		return false;
	end
	return (not offensiveSituation(target)) and (not katameSituation(target));
end

-- 相手ダウンとかふっとびとか
function oiuchiSituation(target)
	local targetEnemy = getReverseTarget(target);
	if (isControllableSituation(targetEnemy))
	then
		return false;
	end
	return (not katameSituation(target));
end

function kaihikekkaiSituation(target)
	local current = tracer[target]:current();
	return isKaihiKekkaiMotion(current.act);
end

function recoverySituation(target)
	-- ダウン中か受身、復帰中
	return true;
end

-- 被ダメ、ガード、グレイズ状況はモーション次第で常に見ておく。
function everyTime(target)
	return true;
end

-- ActionSelector登録用ガード、グレイズ状況判定。
-- see recomendGuard()
function guardSituation(target)
	if (not isControllableSituation(target))
	then
		return false;
	end
	return recommendGuard(target, 100);
end
function gureizuSituation(target)
	return recommendGureizu(target, 100);
end

function isControllableSituation(target)
	local current = tracer[target]:current();
	if (current == nil)
	then
		return true;
	end
	return isControllableMotion(current.act);
end