function onLevelStart()
{
SendMessage( MT_Info, "Objective added" );
SendMessage( MT_Warning, "Hold TAB to view objectives", 10 );
global
LS =
{
room1dooropened = false,
room1powerfixed = false,
room2door1state = false,
room2door2state = false,
room2door3state = false,
room2doorsopened = false,
}
,OBJ_ROOM_1 = ObjectiveAdd( "Find a way to open the door", OS_Hidden )
,OBJ_ROOM_1a = ObjectiveAdd( "Fix power lines for the door", OS_Hidden )
,OBJ_ROOM_2 = ObjectiveAdd( "Find a way to open all 3 doors", OS_Hidden )
,OBJ_ROOM_2a = ObjectiveAdd( "Find a way to bypass all 3 doors", OS_Hidden )
,OBJ_ENDING = ObjectiveAdd( "Get to the flag!", OS_Open )
;
}
function objstate( id, state )
{
if( state == ObjectiveGetState( id ) )
return;
if( state == OS_Open )
{
SendMessage( MT_Info, "Objective added" );
SendMessage( MT_Continued, ObjectiveGetText( id ) );
}
if( state == OS_Done )
{
SendMessage( MT_Info, "Objective completed" );
SendMessage( MT_Continued, ObjectiveGetText( id ) );
}
ObjectiveSetState( id, state );
}
function callent( name, arg )
{
CallEntity( name, arg );
}
//
// ROOM 1
//
function onRoom1Enter(enter)
{
if(!enter)return;
objstate( OBJ_ROOM_1, OS_Open );
}
function updateRoom1Door()
{
if( LS.room1powerfixed == false && LS.room1dooropened )
{
callent( "room1pboxspark", "trigger_enter" );
objstate( OBJ_ROOM_1a, OS_Open );
}
if( LS.room1powerfixed && LS.room1dooropened )
{
callent( "room1pboxspark", "trigger_leave" );
callent( "room1door", "trigger_enter" );
objstate( OBJ_ROOM_1, OS_Done );
}
}
function onRoom1SwitchTop()
{
LS.room1dooropened = true;
updateRoom1Door();
}
function testRoom1PboxTop()
{
return PlayerHasItem( "wrench" );
}
function onRoom1PboxTop()
{
objstate( OBJ_ROOM_1a, OS_Done );
LS.room1powerfixed = true;
updateRoom1Door();
}
//
// SUB
//
function onSubSwitch( on, evname )
{
callent( "subdoor1", evname );
callent( "subdoor2", evname );
}
//
// ROOM 2
//
function onRoom2Enter(enter)
{
if(!enter)return;
objstate( OBJ_ROOM_2, OS_Open );
}
function testRoom2SwitchAny()
{
return LS.room2doorsopened == false;
}
function updateRoom2()
{
if( LS.room2door1state && LS.room2door2state && LS.room2door3state )
{
LS.room2doorsopened = true;
callent( "room2sparks", "trigger_once" );
objstate( OBJ_ROOM_2, OS_Done );
}
}
function onRoom2Exit()
{
objstate( OBJ_ROOM_2, OS_Cancelled );
objstate( OBJ_ROOM_2a, OS_Done );
}
function onRoom2Switch1()
{
callent( "room2door2", "trigger_enter" ); LS.room2door2state = true;
callent( "room2door3", "trigger_switch" ); LS.room2door3state = !LS.room2door3state;
updateRoom2();
}
function onRoom2Switch2()
{
callent( "room2door1", "trigger_enter" ); LS.room2door1state = true;
callent( "room2door2", "trigger_switch" ); LS.room2door2state = !LS.room2door2state;
callent( "room2door3", "trigger_leave" ); LS.room2door3state = false;
updateRoom2();
}
function onRoom2Switch3()
{
callent( "room2door1", "trigger_switch" ); LS.room2door1state = !LS.room2door1state;
callent( "room2door2", "trigger_leave" ); LS.room2door2state = false;
callent( "room2door3", "trigger_enter" ); LS.room2door3state = true;
updateRoom2();
}
//
// END
//
function onLevelEnd(enter)
{
if(!enter)return;
objstate( OBJ_ENDING, OS_Done );
EndLevel( true );
}
Comments