-----------------------------------------------------------------------------
-- Site 11
-----------------------------------------------------------------------------
-- PostStage

function PostStage()
    -- do this stuff first, tells the game that the round is over
    EntGame.EnablePlayerControl(false);
    EntGame.ClearFlag(GF_READYTOSTART);
    EntGame.BindCameraToEntity("IntroCamera");
	
    Sound.Release(sfxCaveGrowl);
   
    end;    
    
-----------------------------------------------------------------------------    
-- Setup

function Setup()	
	-- turn on the "Game running" menu - may not be needed for this game
    EntGame.PushMenu("MenuGameRunning");

    -- load world
    SetupWorld("Maps\\Site11\\Site11.ini", "","","");
    EntGame.CreatePlayerEntities();
	
	-- Do any setup that is specifically for testing.
	if(EntGame.TestingLevels()) then
		Testing();
		end;
    
	entRoot = Game.GetRootEntity();
    entSnow = Entity.FindName(entRoot, "Snow"); 
	
    EntGame.SetGlobalDustColorInitial(1.0, 1.0, 1.0, 1.0);
    EntGame.SetGlobalDustColorFinal  (0.1, 1.0, 1.0, 1.0);
    
    EntGame.SetStageTimer(180);
    
	-- cache animals
	EntGame.LoadAnimal(AID_DALL_SHEEP_M);
	EntGame.LoadAnimal(AID_DALL_SHEEP_F);
	EntGame.LoadAnimal(AID_GRIZZLY_BEAR);
	EntGame.LoadAnimal(AID_WOLVERINE);
	
    -- set stagel parameters
    sfxCaveGrowl= Sound.Load("Sound\\Animals\\BearGrowlInCave2.wav");
	
	   -- setup tournament logic    
    EntGame.StagePrepare();           

    -- show the scene from the intro camera
    EntGame.BindCameraToEntity("IntroCamera");
	entCamera = Entity.FindName(entRoot, "IntroCamera");
	--Camera.JumpToWaypoint(entCamera, "IntroWptAA");   
	Camera.SetSpeed(entCamera, 01.4, .01); 
    -- tell the game the world has loaded
    Entity.GameEventPre(Game.GetRootEntity(), GE_WORLDLOADED, 0);	

    -- wait until the intro dialog is dispatched
    while (EntGame.GetFlag(GF_READYTOSTART) == false) do
        Script.WaitFrame(1);
        end;      
		
	-- do a fade out        
    FadeOut();
    Script.WaitSec(0.5);       
	   
    end;
	
	
---------------------------------------------------------------------------------------------------------------------
 function Intro()
 
	EntGame.PlaySong("Music\\TheMovement.ogg");

	animal = EntGame.SpawnAnimal2(AID_DALL_SHEEP_M, "DecorativePath1", 0, ST_GRAZING, 6+2);
	Animal.FaceEntity(animal, entCamera);
    animal = EntGame.SpawnAnimal2(AID_DALL_SHEEP_M, "DecorativePath2", 0, ST_GRAZING, 6+2);
	
	    -- set up animals for a nice intro-camera view     	
    animala=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath20", 1, ST_GRAZING, 20000, 0, 0, .8);
    animalb=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath19", 0, ST_WPT_WALK, 20000, 3, 0, .8);
    animalc=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath19", 2, ST_GRAZING, 20000, 0, 4, .8);
    animald=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath9",  0, ST_WPT_RUN, 20000, 0, 0, .05);
    animale=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath10", 0, ST_WPT_RUN, 20000, 0, 0, .05);
    animalf=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath11", 0, ST_WPT_RUN, 20000, 0, 0, .05); 
    animalg=EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath19", 0, ST_GRAZING, 20000, -5, 3, .8);

	     
    EntGame.BindCameraToEntity("CountdownCamera3");
    FadeIn();      
    Script.WaitSec(1.0); 

    -- "3"
    Entity.GameEventPre(Game.GetRootEntity(), SSK1_COUNTDOWN_3, 0);   
    Script.WaitSec(1.0);
    
    -- "2"
    Entity.GameEventPre(Game.GetRootEntity(), SSK1_COUNTDOWN_2, 0);  
    EntGame.BindCameraToEntity("CountdownCamera2");
    Script.WaitSec(1.0);
    
    -- "1"
    Entity.GameEventPre(Game.GetRootEntity(), SSK1_COUNTDOWN_1, 0);   
    EntGame.BindCameraToEntity("CountdownCamera1");   
    Script.WaitSec(1.0);
  
    -- "HUNT!"    
	EntGame.DestroyAllAnimals()
    entCamera = Entity.FindName(entRoot, "MainCamera");
    EntGame.BindCameraToEntity(entCamera);    
	Camera.JumpToWaypoint(entCamera, "CamWptAA");
    Camera.SetSpeed(entCamera, 0.0, 0.01);  
    EntGame.BindInputToEntity("Player1");    
    Entity.GameEventPre(Game.GetRootEntity(), SSK1_COUNTDOWN_HUNT, 0);     
    Entity.GameEventPre(Game.GetRootEntity(), SSK1_START, 0);
    
  end;
	
	
-----------------------------------------------------------------------------
-- Use this function for overriding various game parameters (i.e. weapon availability, etc.)
function Testing()
    EntGame.SetPlayerWeapon(0, WS_PISTOL, 	    WID_PISTOL_3);
	EntGame.SetPlayerWeapon(0, WS_SINGLE_RIFLE, WID_SINGLE_RIFLE_3);
    EntGame.SetPlayerWeapon(0, WS_SHOTGUN,	    WID_SHOTGUN_2);	
	EntGame.SetPlayerWeapon(0, WS_AUTO_RIFLE, 	WID_AUTO_RIFLE_3);	
	EntGame.SetPlayerWeapon(0, WS_BOW, 		    WID_BOW_1);
	EntGame.ResetWeaponIcons();
	end;

-----------------------------------------------------------------------------
function Part1()

FadeIn();
 	
	Script.WaitSec(3);
	
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath1");  
	
	Script.WaitSec(3);        
	animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath2");
    Script.WaitSec(2);
	
	--POWERUP
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath5");
	EntGame.CreateAnimalPowerUp(animal, PID_WILEY_VISION_50);
	
    Script.WaitSec(4);        
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath3");    
    Script.WaitSec(4);        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath4");
    animal=EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath5");
	Script.WaitSec(1);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath1");
    Script.WaitSec(4);        
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath3");
    Script.WaitSec(4);
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath2");
    Script.WaitSec(2);        
    EntGame.SpawnAnimal(AID_WOLVERINE, "FollowPath1");
	Script.WaitSec(2);
	
	--POWERUP
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath4");
	EntGame.CreateAnimalPowerUp(animal, PID_2X_FIRE_RATE);
	
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath5");
    Script.WaitSec(2);
    animal=EntGame.SpawnAnimal(AID_WOLVERINE, "FollowPath4");	
	Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath3");
    Script.WaitSec(4);        
    animal=EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath4");
    Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath3");
    Script.WaitSec(3);
    animal = EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath1", WPT_0, ST_WPT_RUN, 0, 0, 0, .4);
	
	Script.WaitSec(1); 
	Sound.Play(sfxCaveGrowl, 1, 100, DS2_CENTER);
    Script.WaitSec(2);        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath2");

	--PREDATOR #1	
	Predator1 = EntGame.SpawnAnimalOnPath(AID_GRIZZLY_BEAR, "FollowPath5", WPT_0, ST_WPT_RUN, 0, 0, 0, .7);
    Animal.FaceEntity(Predator1, entCamera);
    Animal.SetAutoChargeDist(Predator1, 8.0);
	Animal.SetAttackType(Predator1, ATK_STATIC);
	Animal.SetStaticAttackDist(Predator1, 4.5);
	Animal.SetStaticAttackDelay(Predator1, 1.75);	
	Animal.SetPostAttackRand(Predator1, false);
	Animal.SetPostAttackDir(Predator1, -90);
	
    Script.WaitSec(5);
    end;
    
-----------------------------------------------------------------------------
function Part2()
	
	--DEBUG
	--Camera.JumpToWaypoint(entCamera, "CamWptAA");
    --Camera.SetSpeed(entCamera, 0.0, 0.01); 
	
    Camera.StopAtWaypoint(entCamera, "CamWptCC");
    Camera.SetSpeed(entCamera, 1.0, 0.1); 
	
    Script.WaitSec(8);
    
	--PREDATOR #2
	a = EntGame.SpawnAnimalOnPath(AID_WOLVERINE, "FollowPath8", WPT_0, ST_WPT_RUN, 0, 0, 0, .6); 
	Animal.SetAutoChargeDist(a, 10);
	Animal.SetAttackType(a, ATK_STRAFE);
	Animal.SetStrafeAttackDist(a, 4);
	Animal.SetStrafeAttackDelay(a, 1.0);
	
	--POWERUP
    animal = EntGame.SpawnAnimal2(AID_DALL_SHEEP_M, "DecorativePath3", 0, ST_GRAZING, 5);
	EntGame.CreateAnimalPowerUp(animal, PID_WILEY_VISION_50);
	
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath1", WPT_1, ST_WPT_RUN, 0, 1, 0, .4);
    
    -- pan right and shoot some more
    Camera.SetPanOffset(entCamera, 55, 0.5); --(25 is angle, .15 is turning speed)
    Script.WaitSec(1.5);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath6");
    -- pan left and shoot some more
    Camera.SetPanOffset(entCamera, -10, 1.5);
    Script.WaitSec(2);    
    -- pan back to the center
    Camera.SetPanOffset(entCamera, 0, 0.4);
    
    Script.WaitSec(1);

    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath6");
    Script.WaitSec(1);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 1, 1, .5);
    Script.WaitSec(1);
	
	--POWERUP
    animal = EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, -1, -1, .7);
	EntGame.CreateAnimalPowerUp(animal, PID_3X_SCORE);
        
	Script.WaitSec(2.0);
	
	--PREDATOR #3
	a = EntGame.SpawnAnimalOnPath(AID_GRIZZLY_BEAR, "FollowPath8", WPT_0, ST_WPT_RUN, 0, 0, 0, .6); 
	Animal.SetAutoChargeDist(a, 10);
	Animal.SetAttackType(a, ATK_STATIC);
	Animal.SetStaticAttackDist(a, 4.5);
	Animal.SetStaticAttackDelay(a, 1.75);
	Animal.SetPostAttackRand(a, false);
	Animal.SetPostAttackDir(a, -70);	
	
    Script.WaitSec(4.0);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath8");
    Script.WaitSec(2.0);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath7");
    end;
        
-----------------------------------------------------------------------------
function Part3()
    
	--DEBUG
	--Camera.JumpToWaypoint(entCamera, "CamWptCC");
    --Camera.SetSpeed(entCamera, 0.0, 0.007);
	
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath9");
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath10");
    Script.WaitSec(1.5);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath9", WPT_0, ST_WPT_RUN, 0, 1, 1, .8);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath11");
    Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath6");
	
	--POWERUP
    animal = EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath10", WPT_0, ST_WPT_RUN, 0, -1, -1, .6);
	EntGame.CreateAnimalPowerUp(animal, PID_4X_MAGAZINE);
	
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath11", WPT_0, ST_WPT_RUN, 0, -2, -2, .4);
	
    Script.WaitSec(4.0);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath13");
    Script.WaitSec(3);    
        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "ReversePath1");
    Script.WaitSec(1.0); 
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "ReversePath1", WPT_0, ST_WPT_RUN, 0, -.5, -.5, .6);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "ReversePath1");
	EntGame.SpawnAnimalOnPath(AID_WOLVERINE, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 2, 0, 1);	
    Script.WaitSec(1.5); 
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath7", WPT_0, ST_WPT_RUN, 0, 0, 0, .2);
                
    Camera.SetSpeed(entCamera, 0.5, 0.1);
    Camera.StopAtWaypoint(entCamera, "CamWptDD");
     
	EntGame.SpawnAnimalOnPath(AID_WOLVERINE, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 1.5, 0, 1);
	 
    Script.WaitSec(10); -- Travel Time
    
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath6");
    Script.WaitSec(1.5);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, -.5, -.5, .6);
    Script.WaitSec(3);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 1, 1, .4);
    Script.WaitSec(2); 
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath12");
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "ReversePath2", WPT_0, ST_WPT_RUN, 0, .5, 0, .5);
    Script.WaitSec(1.0); 
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "ReversePath3", WPT_0, ST_WPT_RUN, 0, -.5, 0, .5);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath13");
    Script.WaitSec(1.5); 
    end;
        
-----------------------------------------------------------------------------
function Part4() 
	    
	--DEBUG	
	--Camera.JumpToWaypoint(entCamera, "CamWptDD");
    --Camera.SetSpeed(entCamera, 0.0, 0.007);
	
    Script.WaitSec(4); 
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath13");
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath12");
	EntGame.CreateAnimalPowerUp(animal, PID_WILEY_VISION_50);
    Script.WaitSec(4);
    	    
    Camera.SetSpeed(entCamera, 1.0, 0.1); 
    Camera.StopAtWaypoint(entCamera, "CamWptEE"); 
	
	Script.WaitSec(7);
	
	--PREDATOR #4
	a = EntGame.SpawnAnimal(AID_GRIZZLY_BEAR, "FollowPath14");
	Animal.SetAutoChargeDist(a, 10);
	Animal.SetAttackType(a, ATK_STATIC);
	Animal.SetStaticAttackDist(a, 4.0);
	Animal.SetStaticAttackDelay(a, 1.75);
	Animal.SetPostAttackRand(a, false);
	Animal.SetPostAttackDir(a, 70);	
	
    Script.WaitSec(5); 
	
    end;
    
    
-----------------------------------------------------------------------------
function Part5()
 	
	--DEBUG
	--Camera.JumpToWaypoint(entCamera, "CamWptEE");
    --Camera.SetSpeed(entCamera, 0.0, 0.007); 
    
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath14");
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath15");
    Camera.SetSpeed(entCamera, 0.0, 0.1);
    
    Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath16");
    
    Script.WaitSec(3);        
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
	EntGame.CreateAnimalPowerUp(animal, PID_3X_FIRE_RATE);
	
    Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath14");
    
    Script.WaitSec(3);        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath17");
    
    Script.WaitSec(2);        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath16");
    Script.WaitSec(3);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
	
	EntGame.SpawnAnimal(AID_WOLVERINE, "FollowPath14");
	
    Script.WaitSec(2);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath15", WPT_0, ST_WPT_RUN, 0, 0, 0, 0);
    
    -- pan right and shoot some more
    Camera.SetPanOffset(entCamera, 20, 1); --(25 is angle, .15 is turning speed)
        
    Script.WaitSec(3.0);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath16", WPT_0, ST_WPT_RUN, 0, 0, 0, .7);
    Script.WaitSec(4);        
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath19");
	EntGame.CreateAnimalPowerUp(animal, PID_WILEY_VISION_50);
    Script.WaitSec(3);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath20");
    
    Script.WaitSec(4);        
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath16");
    
    Script.WaitSec(2.25);
    
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_F, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    
    Script.WaitSec(2);
    
    animal=EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath16");
	    
    Script.WaitSec(1.5);
    
    EntGame.SpawnAnimal(AID_DALL_SHEEP_F, "FollowPath19");
    
    Script.WaitSec(1.5); 
        
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath19", 0, ST_WPT_RUN, 0, 0, 0, .7);
    
	--POWERUP
    animal = EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath17");
	EntGame.CreateAnimalPowerUp(animal, PID_2X_MAGAZINE);
	
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
    
    Script.WaitSec(1.5);
    
    EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath17", 0, ST_WPT_RUN, 0, 0, 0, .7);
	
	--POWERUP
    animal = EntGame.SpawnAnimalOnPath(AID_DALL_SHEEP_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
	EntGame.CreateAnimalPowerUp(animal, PID_2X_RELOAD_RATE);
	
    Script.WaitSec(2);
    
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");   
    
    Script.WaitSec(1.5);
       
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
    
	--PREDATOR #6
	a = EntGame.SpawnAnimalOnPath(AID_GRIZZLY_BEAR, "FollowPath15", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
	Animal.SetAutoChargeDist(a, 10);
	Animal.SetAttackType(a, ATK_STATIC);
	Animal.SetStaticAttackDist(a, 4.0);
	Animal.SetStaticAttackDelay(a, 1.75);
	Animal.SetPostAttackRand(a, false);
	Animal.SetPostAttackDir(a, 80);	
	
    Script.WaitSec(1.5);
       
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath16");
    
    Script.WaitSec(2); 
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath14");
    Script.WaitSec(1.5);        
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath17");  
	Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath16");
    Script.WaitSec(1);
    EntGame.SpawnAnimal(AID_DALL_SHEEP_M, "FollowPath20");
	
    end;    

-----------------------------------------------------------------------------
-- Main entry point
   
Setup();   
Intro();
Part1();   
Part2();   
Part3();   
Part4();   
Part5();   

