;;------------------------------------------------------------------------------
;;-選択肢用マクロ-----------------------------------------------------------------
;;------------------------------------------------------------------------------

@iscript

//終わった選択肢がある際次の選択肢を解放する
function release_check(){
	
	//選択肢は01から始まるのでチェックは02から始める
	for( var i = 2; i <= f.select_pattern.cnt; i++ ){
		
		//配列名用に文字列に変える
		var str = "%02d".sprintf(i);
		
		var ary = [];
		ary = f.select_pattern[str];	//記述する量が多くなるので変数に入れておく
		
		if( ary.start == true ) continue;	//すでに選択肢が発生していたら処理をしない
		
		var j;
		for( j = 0; j < ary.release.count; j++ ){
			//複数の選択肢を通過しているのが発生条件ならその回数分回す
			if( f.select_pattern[ary.release[j]].end == false ) break;
		}
		
		//ループを最後まで回していたらendがすべてtrueである
		if( j == ary.release.count ){
			f.select_num.add(str);
			ary.start = true;
		}
		
	}
}

//選択肢の順番を入れる関数
function set_release( heroine, story_num, select_num, array){
	
	//ヒロインの判断
	switch(heroine){
	
		//あいり
		case "airi":
			//ストーリーの判断
			switch(story_num){
				case "01":
					//シナリオの判断
					switch(select_num){
						case "02":	array.release = (["01"]);			break;
						case "03":	array.release = (["01"]);			break;
						case "04":	array.release = (["02","03"]);		break;
						case "05":	array.release = (["04"]);			break;
						case "06":	array.release = (["05"]);			break;
						case "07":	array.release = (["05"]);			break;
						case "08":	array.release = (["05"]);			break;
						case "09":	array.release = (["08"]);			break;
						case "10":	array.release = (["09"]);			break;
						case "11":	array.release = (["06","07","10"]);	break;
						case "12":	array.release = (["11"]);			break;
						case "13":	array.release = (["12"]);			break;
						case "14":	array.release = (["12"]);			break;
						case "15":	array.release = (["12"]);			break;
						case "16":	array.release = (["13","14","15"]);	break;
						case "17":	array.release = (["13","14","15"]);	break;
						case "18":	array.release = (["13","14","15"]);	break;
						case "19":	array.release = (["16","17","18"]);	break;
						case "20":	array.release = (["19"]);			break;
						case "21":	array.release = (["20"]);			break;
						case "22":	array.release = (["21"]);			break;
						case "23":	array.release = (["22"]);			break;
						case "24":	array.release = (["23"]);			break;
					}
				break;
			}
		break;
		
		//奈津留
		case "ntur":
			//ストーリーの判断
			switch(story_num){
				case "01":
					//シナリオの判断
					switch(select_num){
						case "02":	array.release = (["01"]);			break;
						case "03":	array.release = (["02"]);			break;
						case "04":	array.release = (["03"]);			break;
						case "05":	array.release = (["03"]);			break;
						case "06":	array.release = (["05"]);			break;
						case "07":	array.release = (["03"]);			break;
						case "08":	array.release = (["05","06","07"]);	break;
						case "09":	array.release = (["08"]);			break;
						case "10":	array.release = (["09"]);			break;
						case "11":	array.release = (["10"]);		break;
						case "12":	array.release = (["10"]);			break;
						case "13":	array.release = (["11","12"]);		break;
						case "14":	array.release = (["11","12"]);		break;
						case "15":	array.release = (["11","12"]);		break;
						case "16":	array.release = (["13","14","15"]);	break;
						case "17":	array.release = (["13","14","15"]);	break;
						case "18":	array.release = (["16","17"]);		break;
						case "19":	array.release = (["18"]);			break;
						case "20":	array.release = (["19"]);			break;
						case "21":	array.release = (["20"]);			break;
					}
				break;
			}
		break;
		
		//サキ
		case "saki":
			//ストーリーの判断
			switch(story_num){
				case "01":
					//シナリオの判断
					switch(select_num){
						case "02":	array.release = (["01"]);			break;
						case "03":	array.release = (["02"]);			break;
						case "04":	array.release = (["03"]);			break;
						case "05":	array.release = (["04"]);			break;
						case "06":	array.release = (["05"]);			break;
						case "07":	array.release = (["06"]);			break;
						case "08":	array.release = (["07"]);			break;
						case "09":	array.release = (["08"]);			break;
						case "10":	array.release = (["09"]);			break;
						case "11":	array.release = (["09"]);			break;
						case "12":	array.release = (["10","11"]);		break;
						case "13":	array.release = (["12"]);			break;
						case "14":	array.release = (["12"]);			break;
						case "15":	array.release = (["13","14"]);		break;
						case "16":	array.release = (["13","14"]);		break;
						case "17":	array.release = (["13","14"]);		break;
						case "18":	array.release = (["15","16","17"]);	break;
						case "19":	array.release = (["15","16","17"]);	break;
						case "20":	array.release = (["18","19"]);		break;
						case "21":	array.release = (["20"]);			break;
						case "22":	array.release = (["21"]);			break;
						case "23":	array.release = (["22"]);			break;
						case "24":	array.release = (["23"]);			break;
					}
				break;
			}
		break;
	}
}


//選択をした選択肢終了のフラグを立て、配列から削除する
function set_end(select){
	//配列から削除
	f.select_num.erase(f.select_num.find(mp.s));
	//終了フラグを入れる
	f.select_pattern[mp.s].end = true;
}

//======================================================================
// クリッカブルマップ用の選択肢
//======================================================================


//選んだ選択肢
function getClickTarget(str=""){
	f.select_heroine = str;
}

//マウスオーバー演出など
function SelectAction(str=""){

	//bs2で使用されているレイヤーを使う
	var layer = kag.fore.layers[7];
	tf.select_over_layer = new global.Layer(kag, layer);

	//画像がある場合
	if(str!=''){
		//見えるようにしないと
		with(tf.select_over_layer){
			.loadImages("image/select/"+str+".png");
			.setSizeToImageSize();
			//.setSize(layer.width, layer.height);
			.setPos(0, 0);
			//.setImageSize(layer.imageWidth, layer.imageHeight);
			//.setImagePos(0, 0);
			//.hitType = htMask;
			.hitThreshold = 256;
			.visible = true;
		}
		//SE
		try kag.se[0].fadeIn(%[storage:"選択", time:100, volume:100, loop:false]);
		catch(e) System.inform(e.message, "se");
	}else{
		//見えないようにしないと
		with(tf.select_over_layer){
			.visible = false;
		}
	}
}

//選択出来ない場合
function unavailable(){
	// マップのやつ
	var layer = kag.fore.layers[6];
	
	f.debug=1;

	// 合成元
	tf.unavailableLayer = new global.Layer(kag, layer);
	tf.unavailableLayer.loadImages('image/map_select/void.png');
	
	if(sf.air_clear == 0)	tf.unavailableLayer = imageMerge(tf.unavailableLayer, "image/select/air@ng.png");
	if(sf.ntu_clear == 0)	tf.unavailableLayer = imageMerge(tf.unavailableLayer, "image/select/ntu@ng.png");
	if(sf.sak_clear == 0)	tf.unavailableLayer = imageMerge(tf.unavailableLayer, "image/select/sak@ng.png");

	with(tf.unavailableLayer){
		.setSize(layer.width, layer.height);
		.setPos(0, 0);
		.setImageSize(layer.imageWidth, layer.imageHeight);
		.setImagePos(0, 0);
		.visible = true;
	}
}

// 画像の合成
function imageMerge(base_layer, target_img){
	// 合成対象
	var layer = new global.Layer(kag, base_layer);
	layer.loadImages(target_img);

	// 合成
	base_layer.pileRect(0,0,layer,0,0,layer.imageWidth,layer.imageHeight,255);

	return base_layer;
}


@endscript


;;選択肢が終わった際に使用するマクロ
;;使用例:@select_end s="01"
;;指定された選択肢終了のフラグを立てるのと配列から削除します。
;;『s』は終わった選択肢を入れます。
@macro name=select_end
@eval exp="set_end(mp.s)"
@endmacro


;;ヒロイン用選択肢の表示
;;『o』はオマケかどうかの判断に使用します
@macro name=heroine_select
@eval exp="f.omake=mp.o;"
@eval exp="kag.autoMode=0;"
;;メッセージウィンドウを消す
@messWindow_off
@bs
@bg t=300

;;マウスオーバーの画像用
@layopt layer=7 page=fore left=0 top=0 visible=true
@image storage="image/select/void.png" layer=7 page=fore visible=true
;;選択できない用(オマケ時のみ)
@layopt layer=6 page=fore left=0 top=0 visible=true
@image storage="image/select/void.png" layer=6 page=fore visible=true
@if exp="mp.o == 1"
@eval exp="unavailable();"
@endif

;;クリッカブルマップ用
@eval exp="kag.fore.layers[5].hitThreshold = 0"
@layopt layer=5 page=fore left=0 top=0
@image storage="image/select/select.png" layer=5 page=fore visible=true
[s]
@endmacro

@return
