-----------------------------------------------------------------------------
-- Stage 1-1
-----------------------------------------------------------------------------

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(smpFly1);
	Sound.Release(smpFly2);
	
    end;    
    
-----------------------------------------------------------------------------    
-- Setup

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

    -- load world
    SetupWorld("Maps\\WorldSavannah\\SavannahCommon.ini", "Maps\\Stage1-1\\Stage1-1.ini","","");
    EntGame.CreatePlayerEntities();
    
    EntGame.SetGlobalDustColorInitial(1.0, 0.81, .75, .55);
    EntGame.SetGlobalDustColorFinal  (0.0, 0.81, .75, .55);
    
    EntGame.SetStageTimer(180);
    
    -- load sounds
    smpFly1  = Sound.Load("Sound\\Environment\\Fly1.wav");
    smpFly2  = Sound.Load("Sound\\Environment\\Fly2.wav");
    
	-- cache animals
	EntGame.LoadAnimal(AID_WILDEBEEST_M);
	EntGame.LoadAnimal(AID_WILDEBEEST_F);

    -- set up animals for a nice intro-camera view       
    animala=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath20", 1, ST_GRAZING, 20000, 0, 0, .8);
    animalb=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath19", 0, ST_WPT_WALK, 20000, 3, 0, .8);
    animalc=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath19", 2, ST_GRAZING, 20000, 0, 4, .8);
    animald=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath9",  0, ST_WPT_RUN, 20000, 0, 0, .05);
    animale=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath10", 0, ST_WPT_RUN, 20000, 0, 0, .05);
    animalf=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath11", 0, ST_WPT_RUN, 20000, 0, 0, .05); 
    animalg=EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath19", 0, ST_GRAZING, 20000, -5, 3, .8); 

    StartupSequence("Music\\Dim Horizon.ogg");

    EntGame.DestroyAllAnimals();
        
    end;

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

	Camera.JumpToWaypoint(entCamera, "CamWptAA");
    Camera.SetSpeed(entCamera, 0.0, 0.1); 
 
    EntGame.SpawnAnimal2(AID_WILDEBEEST_F, "DecorativePath1", 0, ST_GRAZING, 4);
    EntGame.SpawnAnimal2(AID_WILDEBEEST_M, "DecorativePath2", 0, ST_GRAZING, 3);
	
	Script.WaitSec(math.random(3, 4));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath1");  
    
    Script.WaitSec(math.random(3, 4));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath2");
	
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath5");
	
    Sound.Play(smpFly1, 1, DS2_VOLMAX, DS2_CENTER);
	
    Script.WaitSec(math.random(4, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath3");
        
    Script.WaitSec(math.random(4, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath4");
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath5");
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath1");
    
    Script.WaitSec(math.random(3, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath3");
       
    Sound.Play(smpFly2, 1, DS2_VOLMAX, DS2_CENTER);
    
    Script.WaitSec(math.random(4, 5));
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath2");
    
    Script.WaitSec(math.random(3, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath4");
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath5");
    
    Script.WaitSec(math.random(4, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath3");
    
    Sound.Play(smpFly1, 1, DS2_VOLMAX, DS2_CENTER);
        
    Script.WaitSec(math.random(3, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath4");
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath3");
    Script.WaitSec(math.random(2, 3));
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath1", WPT_0, ST_WPT_RUN, 0, 0, 0, .4);
        
    Script.WaitSec(math.random(3, 4));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath2");
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath5");
     
    Script.WaitSec(5);
    end;
    
-----------------------------------------------------------------------------
function Part2()
	
    Camera.SetSpeed(entCamera, 1.0, 0.1); 
    Camera.StopAtWaypoint(entCamera, "CamWptCC");
    Script.WaitSec(8);
    
    EntGame.SpawnAnimal2(AID_WILDEBEEST_M, "DecorativePath3", 0, ST_GRAZING, 5);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath1", WPT_1, ST_WPT_RUN, 0, 1, 0, .4);
    
    -- pan right and shoot some more
    Camera.SetPanOffset(entCamera, 50, 0.5); --(25 is angle, .15 is turning speed)
    Script.WaitSec(1.5);
    EntGame.SpawnAnimal(AID_WILDEBEEST_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(math.random(1, 1.5));
    Sound.Play(smpFly2, 1, DS2_VOLMAX, DS2_CENTER);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath6");
    Script.WaitSec(math.random(.8, 1.2));
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 1, 1, .5);
    Script.WaitSec(math.random(.5, 1.2));
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, -1, -1, .7);
        
    Script.WaitSec(6.0);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath8");
    Script.WaitSec(2.0);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath7");
    end;
        
-----------------------------------------------------------------------------
function Part3()
	
    Camera.SetSpeed(entCamera, 0.0, 0.1);
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath9");
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath10");
    Script.WaitSec(1.5);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath9", WPT_0, ST_WPT_RUN, 0, 1, 1, .8);
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath11");
    Script.WaitSec(2);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath6");
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath10", WPT_0, ST_WPT_RUN, 0, -1, -1, .6);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath11", WPT_0, ST_WPT_RUN, 0, -2, -2, .4);
            
    Script.WaitSec(4.0);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath13");
    Script.WaitSec(3);    
        
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "ReversePath1");
    Script.WaitSec(1.0); 
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "ReversePath1", WPT_0, ST_WPT_RUN, 0, -.5, -.5, .6);
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "ReversePath1");
    Script.WaitSec(1.5); 
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath7", WPT_0, ST_WPT_RUN, 0, 0, 0, .2);
                
    Camera.SetSpeed(entCamera, 0.5, 0.1);
    Camera.StopAtWaypoint(entCamera, "CamWptDD");
        
    Script.WaitSec(10); -- Travel Time
        
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath6");
    Script.WaitSec(1.5);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, -.5, -.5, .6);
    Script.WaitSec(3);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath6", WPT_0, ST_WPT_RUN, 0, 1, 1, .4);
    Script.WaitSec(2); 
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath12");
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "ReversePath2", WPT_0, ST_WPT_RUN, 0, .5, 0, .5);
    Script.WaitSec(1.0); 
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "ReversePath3", WPT_0, ST_WPT_RUN, 0, -.5, 0, .5);
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath13");
    Script.WaitSec(1.5); 
    end;
        
-----------------------------------------------------------------------------
function Part4() 
	    
    Camera.SetSpeed(entCamera, 0.0, 0.1);
    Script.WaitSec(4); 
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath13");
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath12");
    Script.WaitSec(4);
    	    
    Camera.SetSpeed(entCamera, 1.0, 0.1); 
    Camera.StopAtWaypoint(entCamera, "CamWptEE"); 
    Script.WaitSec(12); 
    end;
    
    
-----------------------------------------------------------------------------
function Part5()
 	
	--DEBUG
	--Camera.JumpToWaypoint(entCamera, "CamWptEE");
    --Camera.SetSpeed(entCamera, 0.0, 0.1); 
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath14");
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath15");
    Camera.SetSpeed(entCamera, 0.0, 0.1);
    
    Script.WaitSec(math.random(2, 3));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");
    
    Script.WaitSec(math.random(3, 4));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath14");
    
    Script.WaitSec(math.random(4, 5));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath17");
    
    Script.WaitSec(math.random(1, 2));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");
    Script.WaitSec(math.random(3, 4));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_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_WILDEBEEST_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath16", WPT_0, ST_WPT_RUN, 0, 0, 0, .7);
    Script.WaitSec(4);        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath19");
    Script.WaitSec(3);
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath20");
    
    Script.WaitSec(4);        
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath16");
    
    Script.WaitSec(2.25);
    
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    
    Script.WaitSec(2);
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");
    
    Script.WaitSec(1.5);
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath19");
    
    Script.WaitSec(1.5); 
        
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath19", 0, ST_WPT_RUN, 0, 0, 0, .7);
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath17");
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    
    Script.WaitSec(1.5);
    
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_F, "FollowPath17", 0, ST_WPT_RUN, 0, 0, 0, .7);
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath14", WPT_0, ST_WPT_RUN, 0, 0, 0, 1);
    
    Script.WaitSec(2);
    
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath20");   
    
    Script.WaitSec(1.5);
       
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    
    Script.WaitSec(2.5);
       
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");
    
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");   
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath14");
    Script.WaitSec(math.random(3, 4));        
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath17");      
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath16");
    Script.WaitSec(math.random(2, 3));
    EntGame.SpawnAnimal(AID_WILDEBEEST_M, "FollowPath20");
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimalOnPath(AID_WILDEBEEST_M, "FollowPath15", WPT_0, ST_WPT_RUN, 0, 0, 0, 0);
    Script.WaitSec(math.random(1, 2));
    EntGame.SpawnAnimal(AID_WILDEBEEST_F, "FollowPath16");
    
    end;    

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

