void() func_rotating_use =
{
	if (!self.avelocity)
		self.avelocity = self.movedir;
	else
		self.avelocity = '0 0 0';
};

void() func_rotating_touch =
{
	T_Damage (other, self, self, self.dmg);
};

void() func_rotating =
{
	self.solid = SOLID_BSP;
	self.movetype = MOVETYPE_PUSH;
	setorigin (self, self.origin);
	setmodel (self, self.model);
	self.classname = "func_rotating";
	setsize (self, self.mins, self.maxs);
	if (self.message) {
		precache_sound(self.message);
		self.noise1=self.message;
	} else {
		precache_sound("misc/null.wav");
		self.noise1="misc/null.wav";
	}
	
	if (!self.speed)
		self.speed = 100;

	if (self.spawnflags & 2) // reverse direction
		self.speed = 0 - self.speed;

	if (self.spawnflags & 64) // not solid
		self.solid = SOLID_NOT;

	if (self.dmg) // hurt 'other' when blocked
		self.touch = func_rotating_touch;
	if (!self.dmg)
		self.dmg=2;
	self.blocked = func_rotating_touch;
	self.use = func_rotating_use;

	if (self.spawnflags & 4)
		self.movedir_z = self.speed;
	else if (self.spawnflags & 8)
		self.movedir_x = self.speed;
	else
		self.movedir_y = self.speed;
	if (self.spawnflags & 1)
		self.avelocity = self.movedir;
};

void() func_ladder =
{
	self.solid = SOLID_NOT;
	self.movetype = MOVETYPE_NONE;
	setorigin (self, self.origin);	
	setmodel (self, self.model);
	self.classname = "func_ladder";	
};

void() func_breakable =
{
	self.solid = SOLID_BSP;
	self.movetype = MOVETYPE_PUSH;
	setorigin (self, self.origin);	
	setmodel (self, self.model);
	self.classname = "func_breakable";
}

void() jumppad_touch =
{
	if (other.classname == "player")
	{
		other.velocity = self.speed * self.movedir * 8;
	}
};

void() trigger_jump =
{
	InitTrigger ();
	if (!self.speed)
		self.speed=100;
	self.touch = jumppad_touch;
};

void() toggle_illusionary_use =
{
	if (!self.impulse) {
		setmodel(self,"");
		self.impulse=1;
	} else {
		setmodel(self,self.weaponmodel);
		self.impulse=0;
	}
};

void() func_toggle_illusionary =
{
	self.solid = SOLID_NOT;
	self.movetype = MOVETYPE_NONE;
	setorigin(self,self.origin);
	self.weaponmodel=self.model;
	self.impulse=1;
	self.use=toggle_illusionary_use;
};

void() trigger_portal_touch =
{
	local entity e;
	local vector offset;
	local vector orig;

	if (!self.impulse)
		return;

	e = find(world, targetname, self.target);
	if (!e)
		objerror("trigger_portal: target does not exist\n");
	if (e == self)
		objerror("trigger_portal: target cannot be self\n");
	if (e.origin == '0 0 0')
		objerror("trigger_portal: NULL origin\n");

	sound (other, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);

	offset_x = other.origin_x - self.origin_x;
	offset_y = other.origin_y - self.origin_y;
	offset_z = other.origin_z - self.origin_z;
	orig_x = e.origin_x + offset_x;
	orig_y = e.origin_y + offset_y;
	orig_z = e.origin_z + offset_z;
	orig = orig + 32 * v_forward;
	makevectors (e.angles);
//	orig = orig + 32 * v_forward;
	setorigin(other, orig);
	other.angles = e.mangle;
	other.fixangle = 1;
	other.teleport_time = time + 0.7;
	other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y);
//	other.velocity = v_forward * 200;
	other.flags = other.flags - other.flags & FL_ONGROUND;

	sound (other, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM); // CHAN_VOICE
};

void() trigger_portal_use =
{
	if (self.impulse)
		self.impulse = 0;
	else
		self.impulse = 1;
};

void() trigger_portal =
{
	InitTrigger ();
	if (!self.target)
		objerror("trigger_portal with no target\n");	
	self.use = trigger_portal_use;
	self.touch = trigger_portal_touch;
	if (self.spawnflags & 1)
		self.impulse = 1;
};

void() info_portal_dest =
{
	self.mangle = self.angles;
	self.angles = '0 0 0';
	self.model = "";
	self.origin = self.origin + '0 0 27';
}