Doors that AI can open -- prl_00_door_ai.cog
The basic LEC 00_door.cog modified so that AI (enemies etc.) can open one to four doors with the touched message. This means that an AI walking (or flying) into a door will cause them to open. However the AI can not see through the doors. This cog is useful for doors by windows or when an AI is chasing you and you go through a door. May 2001

# Jedi Knight Cog Script
#
# prl_00_door_ai.cog
# 00_Door.cog - Modified to allow AI to open with Touched message
# Sylvicolus [PRL] May 2001
# startup code fixed [PRL] March 2002
#
# This cog is not supported by LucasArts Entertainment Co.

symbols
	message	startup
	message	activated
	message touched
	message	arrived
	message	timer
	message	blocked

	thing	door0	linkid=0 mask=0x405
	thing	door1	linkid=1 mask=0x405
	thing	door2	linkid=2 mask=0x405
	thing	door3	linkid=3 mask=0x405
	float	moveSpeed=8.0
	float	sleepTime=2.0
	float	lightValue=0.5
	sector	doorSector	local
	int	numDoors=0	local
	int	doorStatus	local
	int	moveStatus	local
	int	i		local
	int	player		local

end

# ========================================================

code

startup:
	player = jkGetLocalPlayer();
	for (i=0; i<=3; i=i+1)
	{
		if (door0[i] >= 0) 
		{
		numDoors = numDoors + 1;
		doorSector = GetThingSector(door0[i]);
		SetSectorAdjoins(doorSector, 0);
		SetSectorLight(doorSector, lightValue, 0.0);
		}
	}
	return;

touched:
   if (GetSourceRef() == player) return; //AI can activate doors with touch
activated:
	call CheckStatus;
	if (moveStatus) return;
	if (doorStatus == 0) {			// all doors are at frame 0
		SetSectorAdjoins(doorSector, 1);
		call OpenDoors;
	}
	return;

arrived:
	call CheckStatus;
	if (moveStatus) return;
	if (doorStatus == numDoors) {		// all doors are at frame 1
		SetTimer(sleepTime);
	} else if (doorStatus == 0) {		// all doors are at frame 0
		SetSectorAdjoins(doorSector, 0);
	}
	return;

blocked:
	call OpenDoors;
	return;

timer:
	call CloseDoors;
	return;

OpenDoors:
	for (i=0; i<=3; i=i+1)
		if (door0[i] >= 0) MoveToFrame(door0[i], 1, moveSpeed);
	return;

CloseDoors:
	for (i=0; i<=3; i=i+1)
		if (door0[i] >= 0) MoveToFrame(door0[i], 0, moveSpeed);
	return;

CheckStatus:
	moveStatus = 0;
	doorStatus = 0;
	for (i=0; i<=3; i=i+1) 
	{
		if (door0[i] >= 0) 
		{
			moveStatus = moveStatus + IsThingMoving(door0[i]);
			doorStatus = doorStatus + GetCurFrame(door0[i]);
		}
	}
	return;

end