/*
An autoport connector e.g. at the edge of a room leading to the edge of another
*/
"use strict";

var GO_Passage = function(w,h,getDestName,relocate){
	this.sprite = new Sprite(null,"Passage");
	this.sprite.collision_flags = 
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
	this.sprite.setBoundingBox(0,0,(w)?parseInt(w):15,(h)?parseInt(h):15);
	this.sprite.game_object = this; // no longer a generic GO

	this.getDestName = getDestName;
	this.relocate = relocate;
};

GO_Passage.prototype = new GameObject(
	new Sprite(null,"Passage"),
	"Passage"
	);

	GO_Passage.prototype.interactions = 
		DEFINE_GAMEOBJECT_INTERACTIONS.AUTOPORT;

// Static helpers to do common coordinate transitions
// for left/right/up/down adjacent-room relocation

GO_Passage.Left = function(sprite){
	// really, (width-1) - (margin-1)
	sprite.x = ((sprite.map_room.width-sprite.map_room.margin)<<4)+14 - sprite.box_right;
};

GO_Passage.Right = function(sprite){
	sprite.x = ((sprite.map_room.margin-1)<<4) + 2 - sprite.box_left;
};

GO_Passage.WaterUp = function(sprite){
	// really, (height-1) - (margin-1)
	sprite.y = ((sprite.map_room.height-sprite.map_room.margin)<<4) + 14 - sprite.box_bottom;
};

GO_Passage.AirUp = function(sprite){
	// really, (height-1) - (margin-1)
	sprite.y = ((sprite.map_room.height-sprite.map_room.margin)<<4) + 14 - sprite.box_bottom - 8; // clearance offset
};

GO_Passage.WaterDown = function(sprite){
	sprite.y = ((sprite.map_room.margin-1)<<4) + 2 - sprite.box_top;
};

GO_Passage.AirDown = function(sprite){
	sprite.y = ((sprite.map_room.margin-1)<<4) + 2 - sprite.box_top + 8; // accounting for head clearance	
};

// Static helpers to generate the most common
// up/down/left/right transitions to the edge
// of an adjacent room, offset by a number of 
// tiles along the edge

GO_Passage.RelocaterLeft = function(yoff){
	return function(sprite){
		GO_Passage.Left(sprite);
		sprite.y += (yoff<<4);
	};
};
GO_Passage.RelocaterRight = function(yoff){
	return function(sprite){
		GO_Passage.Right(sprite);
		sprite.y += (yoff<<4);
	};
};

GO_Passage.RelocaterWaterUp = function(xoff){
	return function(sprite){
		sprite.x += (xoff<<4);
		GO_Passage.WaterUp(sprite);
	};
};
GO_Passage.RelocaterAirUp = function(xoff){
	return function(sprite){
		sprite.x += (xoff<<4);
		GO_Passage.AirUp(sprite);
	};
};

GO_Passage.RelocaterWaterDown = function(xoff){
	return function(sprite){
		sprite.x += (xoff<<4);
		GO_Passage.WaterDown(sprite);
	};
};
GO_Passage.RelocaterAirDown = function(xoff){
	return function(sprite){
		sprite.x += (xoff<<4);
		GO_Passage.AirDown(sprite);
	};
};
