# Jedi Knight Cog Script
#
# 21_EndLevel.cog
#
# Controls ending of the level and setting of goals
#
# [IS]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ========================================================================================


symbols

message  startup
message  killed
message  user7

int      player                          local
sound    goalsnd=Accomplish1.wav         local
sound    wav0=i00je01z.wav               local
sound    wav1=i00je05z.wav               local

thing    jerec                           mask=0xfff

int      i=0                             local

material tip_mat=saberyellow0.mat        local
material side_mat=saberyellow1.mat       local

template tpl_wall=+ssparks_wall          local
template tpl_blood=+ssparks_blood        local
template tpl_saber=+ssparks_saber        local

end

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

code
startup:
   player = GetLocalPlayerThing();

   // Prepare Kyle's yellow lightsaber if light path
   if(jkGetChoice() == 1)
   {
		jkSetSaberInfo(player, side_mat, tip_mat, 0.0128, 0.0128, 0.123, tpl_wall, tpl_blood, tpl_saber);
   }
	jkSetFlags(player, 0x81);

   // Setup the goals first string in cogStrings.uni so the UI knows about it.
   SetInv(player, 99, 21000);
   SetGoalFlags(player, 0, 1);

   // When player starts, give him fists, and a bryar.
   SetInv(player, 1, 1.0);
   SetInv(player, 2, 1.0);
   if(GetInv(player, 11) < 50) SetInv(player, 11, 50.0);

   // Initialize weapon.
   SetFireWait(player, -1);
   SetMountWait(player, 0);
   SetCurInvWeapon(player, 0);
   SelectWeapon(player, 10);

   return;

# ........................................................................................

killed:
   SetGoalFlags(player, 0, 2);
   PlaySoundThing(goalsnd, player, 1.0, -1, -1, 0);
   jkPrintUNIString(player, 350);

   Sleep(8.0);

   // Don't end the level if player is dead.
   if (GetThingHealth(player) <= 0)
      return;

   jkEndLevel(1);

   return;

# ........................................................................................

user7:

   // core is closed, Kyle LOSES
   PlaySoundLocal(wav0, 1.5, 0.0, 0x0);

   // fade to white
   for (i=0; i<=25; i=i+1)
   {
      newColorEffect(0, 0, 0, 0, 0, 0, 10, 10, 10, 1.0);
      Sleep(0.1);
   }

   Sleep(0.5);
   jkEndLevel(0);
   return;

end

