#include"./../System/LIB/Event_Const.dnh"

function GetPreviousScriptDirectory {
	let current = GetCurrentScriptDirectory;
	current = erase(current, length(current)-1);
	
	while(current[length(current)-1] != '/'){
		current = erase(current, length(current)-1);
	}
	return current;
}

let PSD = GetPreviousScriptDirectory;

function SetMovePosition(obj,x,y,weight,max_speed) {
	let distance = GetDistance(ObjRender_GetX(obj),ObjRender_GetY(obj),x,y);
	let angle = atan2(y-ObjRender_GetY(obj), x-ObjRender_GetX(obj));
	while(distance > 1){
		let speed = distance/weight;
		if(speed > max_speed) { speed = max_speed; }
		ObjRender_SetX(obj, ObjRender_GetX(obj) + cos(angle)*speed);
		ObjRender_SetY(obj, ObjRender_GetY(obj) + sin(angle)*speed);
		distance = GetDistance(ObjRender_GetX(obj),ObjRender_GetY(obj),x,y);
		yield;
	}
	ObjRender_SetPosition(obj,x,y,0);
}
task SetMovePosition01(obj,x,y,weight,max_speed) {
	let distance = GetDistance(ObjRender_GetX(obj),ObjRender_GetY(obj),x,y);
	let angle = atan2(y-ObjRender_GetY(obj), x-ObjRender_GetX(obj));
	while(distance > 1){
		let speed = distance/weight;
		if(speed > max_speed) { speed = max_speed; }
		ObjRender_SetX(obj, ObjRender_GetX(obj) + cos(angle)*speed);
		ObjRender_SetY(obj, ObjRender_GetY(obj) + sin(angle)*speed);
		distance = GetDistance(ObjRender_GetX(obj),ObjRender_GetY(obj),x,y);
		yield;
	}
	ObjRender_SetPosition(obj,x,y,0);
}

function GetDistance(x1,y1,x2,y2) {
	return ((x1-x2)^2+(y1-y2)^2)^(1/2);
}
function wait(w) {
	loop(w) { yield; }
}
function waitTimeStop(w) {
	loop(w) {
		while(GetCommonData("TimeStop",false)) { yield; }
		yield;
	}
}