setup.travel = function(travelRequest:LocationTravelRequest){
	State.variables.locationTravelRequest = travelRequest;

	const events = setup.eventsGet(State.variables.locationTravelRequest.tags);
	const eventsResult = setup.eventsExecute(events);

	if(eventsResult.exitCode == EEventsExecuteExitCode.NOT_STOPPED){
		State.variables.time.minutes += State.variables.locationTravelRequest.time;
		setup.gt(State.variables.locationTravelRequest.destination);
		return;
	}

	if(eventsResult.contents){
		setup.gt('TravelEvent',eventsResult.contents,eventsResult.actions);
		return;
	}
}

Macro.add('travel', {
	skipArgs : false,
	handler  : function () {
		try{
			const from = State.variables.location.locationIdentifier;

			const destination:string|string[] = this.args[0];
			let destinationIdentifier:LocationIdentifier;
			if(Array.isArray(destination))
				destinationIdentifier = new LocationIdentifier(destination[0],destination.slice(1));
			else
				destinationIdentifier = new LocationIdentifier(destination);

			
			const time:number = Number.parseInt(this.args[1] ?? 0);
			const tags:string[] = this.args[2] ?? [];
			
			const travelRequest = new LocationTravelRequest(destinationIdentifier,from,time,tags);
			setup.travel(travelRequest);
		}
		catch (ex) {
			return this.error('ERROR in travel-widget: ' + ex.message);
		}
	}
});

Macro.add('travelAbort', {
	skipArgs : false,
	handler  : function () {
		try{
			setup.gt(State.variables.locationTravelRequest.from);
		}
		catch (ex) {
			return this.error('ERROR in travelPartially-widget: ' + ex.message);
		}
	}
});

Macro.add('travelCommence', {
	skipArgs : false,
	handler  : function () {
		try{
			setup.travel(State.variables.locationTravelRequest);
		}
		catch (ex) {
			return this.error('ERROR in travelPartially-widget: ' + ex.message);
		}
	}
});

Macro.add('travelPartially', {
	skipArgs : false,
	handler  : function () {
		try{
			const requestedTravelMinutes:number = this.args[0];
			const currentTravelRequest = State.variables.locationTravelRequest;
			const minutesLeft = Math.max(0,currentTravelRequest.time - requestedTravelMinutes);
			currentTravelRequest.time = minutesLeft;
		}
		catch (ex) {
			return this.error('ERROR in travelPartially-widget: ' + ex.message);
		}
	}
});