// World map script

function WorldMapGui::onWake(%this)
{   
   %this.hideCounter = 0;
   
   $enableDirectInput = "1";
   activateDirectInput();
   
   %this.insideStudio = false;
   $PlayTutorial = false;
   $CurFirstPlay = 1;
   
   %this.loadAwardXML();
   
   %this.showPadlock = false;
     
   // Quaternion transforms hovering each city
   %this.hoverQTransform["London"]    = "0.264815 0.161774 -0.143298 0.93977";
   %this.hoverQTransform["NewYork"]   = "0.00571617 0.274517 -0.424215 0.862931";
   %this.hoverQTransform["Paris"]     = "0.147515 -0.246885 -0.344588 -0.893614";
   %this.hoverQTransform["Mexico"]    = "0.153465 -0.291799 0.487244 -0.808638";
   %this.hoverQTransform["Hollywood"] = "0.136563 0.263998 -0.711009 0.637277";
   %this.hoverQTransform["Tokyo"]     = "0.254573 0.0977441 -0.959778 -0.0668182";
   %this.hoverQTransform["HongKong"]  = "0.252856 0.124274 -0.897822 -0.338431";
   %this.hoverQTransform["Fiji"]      = "-0.119259 0.451161 -0.880733 0.0808754";
   
   // Camera transforms hovering each city
   %this.hoverMTransform["London"]    = "-28.2709 17.9782 47.7098 -0.774749 -0.473292 0.419236 0.697678";
   %this.hoverMTransform["NewYork"]   = "0.404263 41.2358 38.4025 -0.0113119 -0.543252 0.839494 1.05951";
   %this.hoverMTransform["Paris"]     = "-37.2723 -2.65739 43.6444 0.328661 -0.550057 -0.767737 0.930925";
   %this.hoverMTransform["Mexico"]    = "7.27519 46.7852 24.4845 0.260859 -0.495998 0.828214 1.25793";
   %this.hoverMTransform["Hollywood"] = "28.5364 27.5205 40.7392 -0.177209 -0.342572 0.922627 1.75967";
   %this.hoverMTransform["Tokyo"]     = "28.6573 -29.7184 38.3291 -0.255143 -0.097963 0.961928 3.27533";
   %this.hoverMTransform["HongKong"]  = "9.21617 -44.5463 30.12 -0.268713 -0.132067 0.954124 3.83209";
   %this.hoverMTransform["Fiji"]      = "45.0262 -11.2026 -3.64542 0.119651 -0.452644 0.883627 2.97967";
   
   exec("scriptsAndAssets/client/scripts/menu/worldMapGuiMentor.cs");      
   
   // Update the action map
   moveMap.push();
   
   %this.gameCtrl = new GuiContainer() {
      canSaveDynamicFields = "1";
      Enabled = "1";
      className = "WorldGameCtrl";    
      isContainer = "1";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "800 460";
      MinExtent = "1 1";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      lockMouse = "0";
      Margin = "0 0 0 0";
      Padding = "0 0 0 0";
      AnchorTop = "1";
      AnchorBottom = "0";
      AnchorLeft = "1";
      AnchorRight = "0";
      useMouseEvents = "1";
   };
   
   GuiCenter.add(%this.gameCtrl);
   
   // Create a cursor
   %this.gameCtrl.cursor = new GuiBitmapCtrl() {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "50 50";
      MinExtent = "2 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      bitmap = "scriptsAndAssets/data/ui/minigame/hand_cursor";
      wrap = "0";
   };
   
   GuiCenter.add(%this.gameCtrl.cursor);
   
   %this.readProfile();
   
   // World map tutorial
   %this.WMTutorialState = 0;   
   if(PlayerProfile.getFieldValue("RunWMTut"@$CurPlayerNum) $= 0)
   {
      %this.WMTutorialState = 1;
      WMTutorialBoxText.setText(%this.tutText1);//"To move the globe grab it by clicking\nand holding your left mouse button.\nTo rotate it simply drag the mouse.");
      WMTutorialBox.setVisible(true);
      WMTutorialBoxText.setVisible(true);
      
      %this.fadeInTutorial();
   }
      
   if(isObject(ArcBall))
      ArcBall.delete();   
   new LCAArcBall(ArcBall);
   ArcBall.init();   
   
   %this.onResize(getWord(Canvas.extent,0), getWord(Canvas.extent,1));   
   Canvas.setWidescreen(GuiCenter, 100, false);
   
   // Initialize award feedback   
   AwardRoom.addAwardGui(GuiCenter);
   
   // Mentor
   if($RunMentor $= 0)
   {
      Canvas.showCursor();      
      %this.showIntro = true;
      %this.onWakeIntro(true);
   }
   else if($returningFromScene && $CurSceneName $= "SciFiLevel" && $CurTake $= 4)
   {
      Canvas.showCursor();
      %this.showIntro = false;
      %this.onWakeIntro(true);      
   }
   else
   {
      %this.onWake2();
   }
   
   %this.timerID = scheduleObjLCA(WorldMapGui, "HO", 30, "onTimer", 0);   
}

function WorldMapGui::onWake2(%this)
{
   %this.gameCtrl.setVisible(true);
   
   %this.keyPressed = false;
   %this.mouseDragging = false;
   %this.zoomOutAfterTab = false;
   
   %curMousePos = canvas.getCursorPos();
   %rect2 = GuiCenter.getPosition();
   %this.gameCtrl.cursor.setPosition(
      getWord(%curMousePos,0)+1-getWord(%rect2,0), 
      getWord(%curMousePos,1)+1-getWord(%rect2,1));   

   %this.pushToBack(WMStudioButton);
   %this.pushToBack(WMBackMainMenuButton);
   %this.pushToBack(WMBackButton);
  
   // Save initial camera position
   %this.initialCameraTransformPrev = Camera1.getTransform();   
   %this.initialCameraTransform = %this.initialCameraTransformPrev;
      
   // 2D bounding box coordinates of the clapperboards
   %this.clapperPos["HongKong","1"] = "163 115 272 194";
   %this.clapperPos["HongKong","2"] = "217 24 318 90";
   %this.clapperPos["HongKong","3"] = "417 21 514 86";
   %this.clapperPos["HongKong","4"] = "514 70 627 152";

   %this.clapperPos["London","1"] = "180 102 292 181";
   %this.clapperPos["London","2"] = "268 20 373 93";
   %this.clapperPos["London","3"] = "453 44 566 124";
   %this.clapperPos["London","4"] = "478 151 595 245";

   %this.clapperPos["Paris","1"] = "207 157 326 255";
   %this.clapperPos["Paris","2"] = "229 58 348 132";
   %this.clapperPos["Paris","3"] = "406 30 521 130";
   %this.clapperPos["Paris","4"] = "426 142 539 228";

   %this.clapperPos["Tokyo","1"] = "184 165 288 230";
   %this.clapperPos["Tokyo","2"] = "173 61 270 126";
   %this.clapperPos["Tokyo","3"] = "299 15 397 85";
   %this.clapperPos["Tokyo","4"] = "411 84 504 155";

   %this.clapperPos["Fiji","1"] = "160 166 292 251";
   %this.clapperPos["Fiji","2"] = "311 5 422 110";
   %this.clapperPos["Fiji","3"] = "498 44 595 114";
   %this.clapperPos["Fiji","4"] = "476 140 582 235";

   %this.clapperPos["Hollywood","1"] = "135 148 258 219";
   %this.clapperPos["Hollywood","2"] = "123 32 243 116";
   %this.clapperPos["Hollywood","3"] = "524 24 658 109";
   %this.clapperPos["Hollywood","4"] = "549 130 669 228";

   %this.clapperPos["Mexico","1"] = "204 250 323 328";
   %this.clapperPos["Mexico","2"] = "217 72 347 180";
   %this.clapperPos["Mexico","3"] = "456 86 576 190";
   %this.clapperPos["Mexico","4"] = "482 201 600 309";

   %this.clapperPos["NewYork","1"] = "146 134 264 223";
   %this.clapperPos["NewYork","2"] = "224 0 330 52";
   %this.clapperPos["NewYork","3"] = "447 22 555 95";
   %this.clapperPos["NewYork","4"] = "469 115 601 207";

   %this.rotateID = -1;
   %this.animateCloudRotation = 0;
   %this.animateCloudID = -1;
   %this.zoomInID  = -1;
   %this.zoomOutID = -1;
   %this.toggleID = -1;
   
   %this.animatingFeedback = false;
   
   %this.canIPlaySound = false;
   %this.rotateSound = "";
   %this.soundPlayingForMouse = false;
   %this.soundPlayingForKeyb = false;
   %this.mousePosForDrag = "0 0";
   
   %this.interpT = 0;
   
   %this.turnDelayKeyb = 0;
   %this.turnDelayMouse = 0;

   //scheduleObjLCA(%this, "HO", 1000, "onRotate", 0);
   
   // Why time was set to 3000?? 
   %this.checkMousePosID = scheduleObjLCA(%this, "HO", 100, "checkMousePos", 0);   
   
   $WorldMapStartTime = getSimTime();
   %this.onRotate();
   %this.AnimateClouds();
      
   %this.hideAll();
   
   %this.loadedLevel = false;   
   %this.overObj = "";
   
   if(!$returningFromScene)
      %this.update();
   else
   {
      // Evaluate awards gained
      %this.evaluateAwards();
      
      %numStars = $CurPlayerStars - $StarsWonInTake;
      %this.updateAwards(%numStars, false);
   }
   
   if($ShowWorldMapClapperboard)
   {
      %this.playClapperboard();
      $ShowWorldMapClapperboard = false;
   }
   
   if($returningFromScene)
   {
      %obj = ($WorldMapZoomedIn);
      %this.selectScene(%obj, 1/*0.99*/);
      
      return;
   }
   
   $WorldMapZoomedIn = false;
   $WorldGameGuiClicked = false;
   $WorldMapGuiBelow460 = false;
   $WorldGameHoverCity = false;
      
   %this.particleCounter = 0;
   
   %this.setInitialPos();   
   
   %this.rotateByKeybID = scheduleObjLCA(WorldMapGui, "HO", 30, "onRotateByKeyb", 0);

   //to provoke cursor to hide on hideCursor
   //$mouseLeftWindow = true;
   Canvas.hideCursor();  
}

function WorldMapGui::onSleep(%this)
{
   // pop the keymaps
   moveMap.pop();
   
   cancelScheduleLCA(%this.rotateID);
   cancel(%this.animateCloudID);
   cancelScheduleLCA(%this.zoomInID);
   cancelScheduleLCA(%this.zoomOutID);
   cancelScheduleLCA(%this.toggleID);
   cancelScheduleLCA(%this.timerID);
   cancelScheduleLCA(%this.rotateByKeybID);
   cancelScheduleLCA(%this.checkMousePosID);

   if(isObject(%this.gameCtrl.cursor))   
      %this.gameCtrl.cursor.setVisible(false);
      
   if(isObject(ArcBall))
      ArcBall.delete();      

   //lockMouse(false);   
   WorldMapGui.showCursor();
}

// Set initial position
function WorldMapGui::setInitialPos(%this)
{
   ArcBall.setCurTransform(%this.hoverQTransform["Paris"]);
/*   
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);   
   
   %startPos = Canvas.getExtent();
   %startPosX = getWord(%startPos,0)/2;
   %startPosY = getWord(%startPos,1)/2;
   ArcBall.onMouseDown(%startPosX, %startPosY);
      
   %newPosX = %startPosX - (110*%winScaleX);
   %newPosY = %startPosY + (85*%winScaleY); // 75
   ArcBall.onMouseMove(%newPosX, %newPosY, Camera1);
   ArcBall.onMouseUp(); */
}

function WorldMapGui::readProfile(%this)
{
   switch$($CurPlayerNum)
   {
      case 1:
         $RunMentor              = PlayerProfile.RunMentor1;
         $CurFirstPlay           = PlayerProfile.FirstPlay1;
         $CurPlayerUScene        = PlayerProfile.PlayerUScene1;
         $CurPlayerGangsterUTake = PlayerProfile.PlayerGangsterUTake1;
         $CurPlayerSpyUTake      = PlayerProfile.PlayerSpyUTake1;
         $CurPlayerKungFuUTake   = PlayerProfile.PlayerKungFuUTake1;
         $CurPlayerMusicalUTake  = PlayerProfile.PlayerMusicalUTake1;
         $CurPlayerDinosaurUTake = PlayerProfile.PlayerDinosaurUTake1;
         $CurPlayerSciFiUTake    = PlayerProfile.PlayerSciFiUTake1;
         $CurPlayerWesternUTake  = PlayerProfile.PlayerWesternUTake1;
         $CurPlayerMonsterUTake  = PlayerProfile.PlayerMonsterUTake1;
         $CurPlayerStars         = PlayerProfile.PlayerStars1;
      case 2:
         $RunMentor              = PlayerProfile.RunMentor2;
         $CurFirstPlay           = PlayerProfile.FirstPlay2;
         $CurPlayerUScene        = PlayerProfile.PlayerUScene2;
         $CurPlayerGangsterUTake = PlayerProfile.PlayerGangsterUTake2;
         $CurPlayerSpyUTake      = PlayerProfile.PlayerSpyUTake2;
         $CurPlayerKungFuUTake   = PlayerProfile.PlayerKungFuUTake2;
         $CurPlayerMusicalUTake  = PlayerProfile.PlayerMusicalUTake2;
         $CurPlayerDinosaurUTake = PlayerProfile.PlayerDinosaurUTake2; 
         $CurPlayerSciFiUTake    = PlayerProfile.PlayerSciFiUTake2;
         $CurPlayerWesternUTake  = PlayerProfile.PlayerWesternUTake2;
         $CurPlayerMonsterUTake  = PlayerProfile.PlayerMonsterUTake2;        
         $CurPlayerStars         = PlayerProfile.PlayerStars2;         
      case 3:
         $RunMentor              = PlayerProfile.RunMentor3;
         $CurFirstPlay           = PlayerProfile.FirstPlay3;
         $CurPlayerUScene        = PlayerProfile.PlayerUScene3;
         $CurPlayerGangsterUTake = PlayerProfile.PlayerGangsterUTake3;
         $CurPlayerSpyUTake      = PlayerProfile.PlayerSpyUTake3;
         $CurPlayerKungFuUTake   = PlayerProfile.PlayerKungFuUTake3;
         $CurPlayerMusicalUTake  = PlayerProfile.PlayerMusicalUTake3;
         $CurPlayerDinosaurUTake = PlayerProfile.PlayerDinosaurUTake3;   
         $CurPlayerSciFiUTake    = PlayerProfile.PlayerSciFiUTake3;
         $CurPlayerWesternUTake  = PlayerProfile.PlayerWesternUTake3;
         $CurPlayerMonsterUTake  = PlayerProfile.PlayerMonsterUTake3;      
         $CurPlayerStars         = PlayerProfile.PlayerStars3;         
      case 4:
         $RunMentor              = PlayerProfile.RunMentor4;
         $CurFirstPlay           = PlayerProfile.FirstPlay4;
         $CurPlayerUScene        = PlayerProfile.PlayerUScene4;
         $CurPlayerGangsterUTake = PlayerProfile.PlayerGangsterUTake4;
         $CurPlayerSpyUTake      = PlayerProfile.PlayerSpyUTake4;
         $CurPlayerKungFuUTake   = PlayerProfile.PlayerKungFuUTake4;
         $CurPlayerMusicalUTake  = PlayerProfile.PlayerMusicalUTake4;
         $CurPlayerDinosaurUTake = PlayerProfile.PlayerDinosaurUTake4;    
         $CurPlayerSciFiUTake    = PlayerProfile.PlayerSciFiUTake4;
         $CurPlayerWesternUTake  = PlayerProfile.PlayerWesternUTake4;
         $CurPlayerMonsterUTake  = PlayerProfile.PlayerMonsterUTake4;     
         $CurPlayerStars         = PlayerProfile.PlayerStars4;         
   }   
}

function MapClapper::onStoppedAtStart(%this)
{
   MapClapper.setVisible(false);
   MapBoard.setVisible(false);
   
   if($returningFromScene)
   {
      $returningFromScene = false;      
      
      if(!WorldMapGui.showStarsGained($CurTake))
      {
         WorldMapGui.showUnlockedScenes();
         WorldMapGui.update();
      }
   }   
}

function WorldMapGui::playClapperboard(%this)
{
   %path = "scriptsAndAssets/data/ui/clapperboard/clapper.jpg";
   MapClapper.setDML(%path);
   MapClapper.forward();
   
   if(OutroGui.playedMinigame)
      %path = "scriptsAndAssets/data/ui/clapperboard/minigame/Minigame_end.jpg";   
   else
      %path = "scriptsAndAssets/data/ui/clapperboard/inoutro/" @ $CurSceneName @ "_intro_take" @ $CurTake @ ".jpg";
      
   MapBoard.setDML(%path);
   MapBoard.forward();

   MapClapper.setVisible(true);
   MapBoard.setVisible(true);
   
   %this.schedule(250, "playClapperboard2");
}

function WorldMapGui::playClapperboard2(%this)
{
   MapClapper.playRev(1);
   MapBoard.playRev(1);   
}

function WorldMapGui::update(%this)
{        
   %this.readProfile();
   
   %this.updateAwards($CurPlayerStars - $StarsWonInTake, true);  
}

function WorldMapGui::updateAwards(%this, %stars, %showAwardsStars)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);   
   
   AwardsBigStarNum.setText(%stars);
}

function WorldMapGui::updateClapperboards(%this, %hide)
{
   %city = $WorldMapZoomedIn;
   
   if(%hide)
   {
      for(%j = 1; %j <= 4; %j++)
      {
         %obj = %city @ "_take_" @ %j @ "_clapperboard";
         %this.SetHidden(%obj, true);         
         %obj = %city @ "_take_" @ %j @ "_filmed";
         %this.SetHidden(%obj, true);         
         %obj = %city @ "_take_" @ %j @ "_filmedrollover";
         %this.SetHidden(%obj, true);         
         %obj = %city @ "_take_" @ %j @ "_grayedout";
         %this.SetHidden(%obj, true);         
         %obj = %city @ "_take_" @ %j @ "_rollover";
         %this.SetHidden(%obj, true);
         
         for(%k = 1; %k <= 5; %k++)
         {
            %obj = %city @ "_take_" @ %j @ "_star_" @ %k @ "_grayedout";
            %this.SetHidden(%obj, true);
            %obj = %city @ "_take_" @ %j @ "_star_" @ %k;
            %this.SetHidden(%obj, true);
         }
      }
      return;
   }   
      
   switch$(%city)
   {      
      case "London"   : %unlockedTakes = $CurPlayerMusicalUTake;
      case "NewYork"  : %unlockedTakes = $CurPlayerGangsterUTake;
      case "Paris"    : %unlockedTakes = $CurPlayerSpyUTake;
      case "Mexico"   : %unlockedTakes = $CurPlayerWesternUTake;
      case "Hollywood": %unlockedTakes = $CurPlayerSciFiUTake;
      case "Tokyo"    : %unlockedTakes = $CurPlayerMonsterUTake;
      case "HongKong" : %unlockedTakes = $CurPlayerKungFuUTake;
      case "Fiji"     : %unlockedTakes = $CurPlayerDinosaurUTake;
   }
   
   switch$(%city)
   {
      case "London"   : %tmp = "PlayerProfile.Player" @ "Musical";
      case "NewYork"  : %tmp = "PlayerProfile.Player" @ "Gangster";
      case "Paris"    : %tmp = "PlayerProfile.Player" @ "Spy";
      case "Mexico"   : %tmp = "PlayerProfile.Player" @ "Western";
      case "Hollywood": %tmp = "PlayerProfile.Player" @ "SciFi";
      case "Tokyo"    : %tmp = "PlayerProfile.Player" @ "Monster";
      case "HongKong" : %tmp = "PlayerProfile.Player" @ "KungFu";
      case "Fiji"     : %tmp = "PlayerProfile.Player" @ "Dinosaur";
   }
   %tmp2 = "%unlockedStars = " @ %tmp @ "StarsTake" @ $CurPlayerNum @ ";";      
   eval(%tmp2);      
      
   for(%j = 1; %j <= 4; %j++)
   {
      if(%unlockedTakes >= %j && getWord(%unlockedStars, %j-1) > 0)
         %obj = %city @ "_take_" @ %j @ "_filmed";
      else if(%unlockedTakes >= %j)
         %obj = %city @ "_take_" @ %j @ "_clapperboard";         
      else
         %obj = %city @ "_take_" @ %j @ "_grayedOut";
      %this.SetHidden(%obj, false);
            
      for(%k = 1; %k <= 5; %k++)
      {
         if($returningFromScene $= true && $CurTake $= %j)
         {
            %numStars = $StarsWonInTake;
            if(getWord(%unlockedStars, %j-1)-%numStars>= %k)
            {
               %obj = %city @ "_take_" @ %j @ "_star_" @ %k;
               %this.SetHidden(%obj, false);           
            }
            else
            {
               %obj = %city @ "_take_" @ %j @ "_star_" @ %k @ "_grayedout";
               %this.SetHidden(%obj, false);
            }
         }
         else
         {
            if(getWord(%unlockedStars, %j-1) >= %k)
            {
               %obj = %city @ "_take_" @ %j @ "_star_" @ %k;
               %this.SetHidden(%obj, false);           
            }
            else
            {
               %obj = %city @ "_take_" @ %j @ "_star_" @ %k @ "_grayedout";
               %this.SetHidden(%obj, false);
            }
         }
      }
   }
}

function WorldMapGui::hideAll(%this)
{
   %numCities = 8;   
   %cities[1] = "Paris"; 
   %cities[2] = "Fiji";
   %cities[3] = "London";
   %cities[4] = "HongKong";   
   %cities[5] = "Mexico";   
   %cities[6] = "Tokyo";
   %cities[7] = "NewYork";
   %cities[8] = "Hollywood";
   
   %this.addDummies();

   // Hide locked cities
   for(%i = 1; %i <= %numCities; %i++)
   {
      // TODO
      %comp = 0;
      if($SceneJustUnlocked $= true)
         %comp = $LastUnlockedScene;
      else
         %comp = $CurPlayerUScene;
         
      if(%comp >= %i)         
//      if($CurPlayerUScene >= %i)
      {
         %this.SetHidden((%cities[%i] @ "_grayedout"), true);
         %this.SetHidden(%cities[%i], false);
      }
      else
      {
         %this.SetHidden((%cities[%i] @ "_grayedout"), false);         
         %this.SetHidden(%cities[%i], true);
         
         // Hide dummy obj
//         %objn = %cities[%i] @ "_click_dummy";
//         %objn.delete();
      }
   }
      
   // Hide all takes, stars and back button states
   for(%i = 1; %i <= %numCities; %i++)
   {
      for(%j = 1; %j <= 4; %j++)
      {
         %obj = %cities[%i] @ "_take_" @ %j @ "_clapperboard";
         %this.SetHidden(%obj, true);         
         %obj = %cities[%i] @ "_take_" @ %j @ "_filmed";
         %this.SetHidden(%obj, true);         
         %obj = %cities[%i] @ "_take_" @ %j @ "_filmedrollover";
         %this.SetHidden(%obj, true);         
         %obj = %cities[%i] @ "_take_" @ %j @ "_grayedout";
         %this.SetHidden(%obj, true);         
         %obj = %cities[%i] @ "_take_" @ %j @ "_rollover";
         %this.SetHidden(%obj, true);
         
         for(%k = 1; %k <= 5; %k++)
         {
            %obj = %cities[%i] @ "_take_" @ %j @ "_star_" @ %k @ "_grayedout";
            %this.SetHidden(%obj, true);
            %obj = %cities[%i] @ "_take_" @ %j @ "_star_" @ %k;
            %this.SetHidden(%obj, true);
         }
      }
   }
   
   // Hide tutorial clapperboards
   %obj = Tutorial_clapperboard;
   %this.SetHidden(%obj, true);
   %obj = Tutorial_clapperboard_rollover;
   %this.SetHidden(%obj, true);
}

/*
function WorldMapGui::goToMainMenu(%this)
{
   MainMenuGui.goHome();
   MainMenuGui.pushThread(map_menu_thread);
}
*/

//Reset the settings for all the cameras to default
function WorldMapGui::initCameras(%this) 
{
   // Set the reference object to the cameras
   %this.setCamShape(WMCam0, %this.camShape1);   
   
   // Set an object to be attached to the WMCam0, this object will
   // have the same position of the active camera (considering animation)
   WMCam0.setAttachedObject(AttachedCamera);
}

function WorldMapGui::setCamShape(%this, %obj, %camShape)
{
   %obj.setRefObject(%camShape);
   %obj.spriteSize = 0 SPC 0;
   %obj.framesPerSec = 0;
   %obj.framesCount = 1;
}

// Callback for resizing events
function WorldMapGui::onResize(%this, %width, %height)
{
   if(isObject(ArcBall))
      ArcBall.setWindow(%width, %height, 1);

   %this.updateSpeechBubble();   

   Canvas.setWidescreen(GuiCenter, 1000, true);
}

function WorldMapGui::onZoomIn(%this, %obj)
{
   switch$(%obj.getName())
   {
      case "London"   : %transf = "-14.43 7.26 27.54 1 0 0 0";
      case "NewYork"  : %transf = "0.381266 21.2924 22.1209 0.172329 0.187046 0.967118 1.08976787698";
      case "Paris"    : %transf = "-18.1387 1.74136 25.7163 -0.257778 0.462483 -0.848328 0.23697033386";
      case "Mexico"   : %transf = "2.88231 22.2585 14.3176 0.655851 -0.0642335 0.752153 1.34225069723";
      case "Hollywood": %transf = "14.8441 12.0457 22.4569 0.180427 -0.0265626 0.98323 1.94904408229";
      case "Tokyo"    : %transf = "15.9043 -14.5356 23.8894 0.119 0.0494849 0.99166 3.26610444243";
      case "HongKong" : %transf = "4.25734 -19.8247 15.2072 0.325369 -0.391217 0.860862 3.75708301431";
      case "Fiji"     : %transf = "17.8955 -9.9137 1.80295 0.549346 -0.200628 0.811152 3.50764055761";      
   }
   
   if($SceneJustUnlocked $= true)
      %this.interpT += 0.02;   
   else
   if(%this.zoomOutAfterTab $= true)
      %this.interpT += 0.1;
   else
      %this.interpT += 0.02;
   
   ArcBall.interpolate(%this.savedCameraTransform, %transf, Camera1, %this.interpT);   
   
   if(%this.interpT < 1)
      %this.zoomInID = scheduleObjLCA(%this, "HO", 15, "onZoomIn", 1, %obj);   
   else
   {
      cancelScheduleLCA(%this.zoomInID);
      
//      %this.gameCtrl.cursor.setVisible(false);
//      Canvas.showCursor();
      %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
      //WorldMapGui.hideCursor();
      
      %this.interpT = 1;
      ArcBall.interpolate(%this.savedCameraTransform, %transf, Camera1, %this.interpT);
      
      // Hide dummy obj
      %objn = %obj.getName() @ "_click_dummy";
      if(isObject(%objn)) %objn.delete();      
      
      if(%this.unlockCity $= true)
      {
         scheduleObjLCA(%this, "HO", 500, "finishUnlockCity", 1, %obj);
      }
      else
      {
         %this.updateClapperboards(false);
               
         if($WorldMapZoomedIn $= "Paris" && $CurFirstPlay $= 0)
            %this.SetHidden(Tutorial_clapperboard, false);
            
         // End world map tutorial
         if(%this.WMTutorialState > 0)
         {
            %this.WMTutorialState = 0;
            %this.fadeOutTutorial();            
            scheduleObjLCA(%this, "HO", 500, "hideTutorial", 0);
         }
         
         // Hide back to main menu button
         WMBackMainMenuButton.setVisible(false);
         WMBackButton.setVisible(true);

         %this.zoomInID = -1;
         %this.tabHit = false;
      }
   }
}

// Fade in tutorial text
function WorldMapGui::fadeInTutorial(%this)
{
   WMTutorialBox.animateAlpha(1, 0, 500, "0 0");
   WMTutorialBoxText.animateAlpha(1, 0, 500, "0 0");   
}

// Fade out tutorial text
function WorldMapGui::fadeOutTutorial(%this)
{
   WMTutorialBox.animateAlpha(0, 0, 500, "0 0");
   WMTutorialBoxText.animateAlpha(0, 0, 500, "0 0");   
}

// Hide the tutorial window and text
function WorldMapGui::hideTutorial(%this)
{
   PlayerProfile.setFieldValue("RunWMTut"@$CurPlayerNum, 1);
   SavePlayerProfile();
   
   WMTutorialBox.setVisible(false);
   WMTutorialBoxText.setVisible(false);   
}

function WorldMapGui::onZoomOut(%this)
{      
//   if(%this.zoomOutAfterTab $= true)
//      %this.interpT += 0.1;
//   else
      %this.interpT += 0.02;
   
   if(%this.zoomOutAfterTab $= true)
      %dest = %this.initialCameraTransform;
   else
      %dest = %this.savedCameraTransform;
   
   %dest = %this.hoverMTransform[$WorldMapZoomedIn];
   
   ArcBall.interpolate(%this.zoomOutSavedCameraTransform, %dest, Camera1, %this.interpT);
   
   if(%this.interpT < 1)
      %this.zoomOutID = scheduleObjLCA(%this, "HO", 15, "onZoomOut", 0);   
   else
   {
      cancelScheduleLCA(%this.zoomOutID);
      
      %this.interpT = 1;
      ArcBall.interpolate(%this.zoomOutSavedCameraTransform, %dest, Camera1, 1);
      
      %this.zoomOutAfterTab = false;
      
      ArcBall.setCurTransform(%this.hoverQTransform[$WorldMapZoomedIn]);
      
      // Hide back button
      %this.hideAll();
      
      // Show back to main menu button
      WMBackButton.setVisible(false);
      WMBackMainMenuButton.setVisible(true);
      
      $WorldMapZoomedIn = false;
      %this.zoomOutID = -1;
      %this.onRotate();
      
      if(!isEventPending(%this.rotateByKeybID))
         %this.rotateByKeybID = scheduleObjLCA(%this, "HO", 30, "onRotateByKeyb", 0);
   }
}

function WorldGameCtrl::onMouseEnter(%this, %modifier, %worldPosition, %mouseClicks)
{
   if($WorldGameGuiHoverCity $= true || $WorldMapZoomedIn !$= false)
   {
      if(WorldMapGui.showPadlock)
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/padlock");
      else
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
         
      //WorldMapGui.hideCursor();      
//      %this.cursor.setVisible(false);
//      Canvas.showCursor();      
      return;
   }
         
   if(!WorldMapGui.showPadlock)
   {
      if($WorldGameGuiClicked $= true)
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");   
      else
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
   }
   
   %this.cursor.setVisible(true);
   //lockMouse(true);
   //WorldMapGui.hideCursor();
}

function WorldGameCtrl::onMouseMove(%this, %modifier, %worldPosition, %mouseClicks)
{
   if($OnResumeDlg || $OnExitDlg)
      return;
      
   WorldMapGui.hideCursor();
   
   if($WorldMapZoomedIn !$= false)
   {
      %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
      //WorldMapGui.hideCursor();      
//      %this.cursor.setVisible(false);
//      lockMouse(false);
//      Canvas.showCursor();      
   }
   else
   {    
      if($WorldGameGuiHoverCity !$= true && $WorldMapZoomedIn $= false)
      {
//         if($WorldGameGuiClicked $= true)
//            %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");   
//         else
//            %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
         
         if($WorldMapGuiBelow460 $= false)
         {
            %this.cursor.setVisible(true);
            //WorldMapGui.hideCursor();
         }
      }
      else
      {
//         %this.cursor.setVisible(true);
//         Canvas.hideCursor();        
         if(WorldMapGui.showPadlock)
            %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/padlock");
         else      
            %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
            
         WorldMapGui.hideCursor();
//         %this.cursor.setVisible(false);
//         Canvas.showCursor();
      }
   }
   
   //+1 is to avoid clicking always on the hand
//   %this.cursor.setPosition(getWord(%worldPosition, 0)+1, getWord(%worldPosition, 1)+1);
   WMCamMouseHandler.onMouseMove(%modifier, %worldPosition, %mouseClicks);
}

function WorldGameCtrl::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
   if($WorldMapZoomedIn $= false)
   {   
      $WorldGameGuiClicked = true;
      if(WorldMapGui.gameCtrl.cursor.bitmap !$= "scriptsAndAssets/data/ui/minigame/padlock")
      {
         if(!$OnResumeDlg && !$OnExitDlg)
            %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");
      }
   }
   WMCamMouseHandler.onMouseDown(%modifier, %worldPosition, %mouseClicks);
}

function WorldGameCtrl::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks )
{
   if($WorldMapZoomedIn $= false)
   {      
      $WorldGameGuiClicked = false;

      if(!WorldMapGui.showPadlock)
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
      else
         %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/padlock");
            
      // Avoid the mouse dragging to get stuck
      if(WorldMapGui.mouseDragging)
      {
          WorldMapGui.canIPlaySound = false;      
          WorldMapGui.mouseDragging = false;
          
          if(!(WorldMapGui.animatingFeedback $= true || WorldMapGui.unlockCity $= true))
            ArcBall.onMouseUp();
      }      
   }
   WMCamMouseHandler.onMouseUp(%modifier, %worldPosition, %mouseClicks);
}
/*
function WorldGameCtrl::onMouseLeave(%this, %modifier, %worldPosition, %mouseClicks)
{
   if($WorldMapZoomedIn !$= false)
      return;
   
   if($WorldGameGuiClicked $= true)
      %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");   
   else
      %this.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
      
   %this.cursor.setVisible(false);
   Canvas.showCursor();
}
*/
function WMCamMouseHandler::onMouseMove(%this, %modifier, %worldPosition, %mouseClicks)
{
   if($OnResumeDlg || $OnExitDlg)
      return;
         
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   if(WorldMapGui.animatingFeedback $= true || WorldMapGui.unlockCity $= true)
      return;
      
   if(WorldMapGui.interpT > 0 && WorldMapGui.interpT < 1)
      return;
   
   // Get mouse position
   %mouseX = getWord(%worldPosition,0);
   %mouseY = getWord(%worldPosition,1);
           
   %obj = WorldMapGui.overObj;
   if(%obj == 0 || !isObject(%obj))
      return;
/*   if(%obj.clickable)
   {
      if($WorldGameGuiClicked $= false)
         $WorldGameGuiHoverCity = true;
      else
         $WorldGameGuiHoverCity = false;
         
	   if(WorldMapGui.overObj !$= %obj)
	   {
	      sfxPlay(SFX_OVER);
	      WorldMapGui.overObj = %obj;
	   }
   }
   else
   {
      $WorldGameGuiHoverCity = false;
      WorldMapGui.overObj = "";
   } */
   if($WorldMapZoomedIn !$= false) //Couldn't you just say this $= true. cause not equal to false just gets confusing.
   {      
	  %this.canIPlaySound = false;
      if($WorldMapZoomedIn $= "Paris")
      {      
         %tut  = Tutorial_clapperboard;
         %tutr = Tutorial_clapperboard_rollover;
      }
      
      if($WorldMapZoomedIn $= "Paris" && 
         %obj.getName() $= "Tutorial_clapperboard" &&
         $CurFirstPlay $= 0)
      {         
         WorldMapGui.SetHidden(%tut,  true);
         WorldMapGui.SetHidden(%tutr, false);
      }
      else
      {
         for(%j = 1; %j <= 4; %j++)
         {
            %clap   = $WorldMapZoomedIn @ "_take_" @ %j @ "_clapperboard";
            %clapf  = $WorldMapZoomedIn @ "_take_" @ %j @ "_filmed";
            %clapfr = $WorldMapZoomedIn @ "_take_" @ %j @ "_filmedrollover";
            %clapr  = $WorldMapZoomedIn @ "_take_" @ %j @ "_rollover";
            %clapg  = $WorldMapZoomedIn @ "_take_" @ %j @ "_grayedout";
            
            switch$($WorldMapZoomedIn)
            {
               case "London"   : %unlockedTakes = $CurPlayerMusicalUTake;
               case "NewYork"  : %unlockedTakes = $CurPlayerGangsterUTake;
               case "Paris"    : %unlockedTakes = $CurPlayerSpyUTake;
               case "Mexico"   : %unlockedTakes = $CurPlayerWesternUTake;
               case "Hollywood": %unlockedTakes = $CurPlayerSciFiUTake;
               case "Tokyo"    : %unlockedTakes = $CurPlayerMonsterUTake;
               case "HongKong" : %unlockedTakes = $CurPlayerKungFuUTake;
               case "Fiji"     : %unlockedTakes = $CurPlayerDinosaurUTake;
            }
            
            switch$($WorldMapZoomedIn)
            {
               case "London"   : %city = "London";    %tmp = "PlayerProfile.Player" @ "Musical";
               case "NewYork"  : %city = "NewYork";   %tmp = "PlayerProfile.Player" @ "Gangster";
               case "Paris"    : %city = "Paris";     %tmp = "PlayerProfile.Player" @ "Spy";
               case "Mexico"   : %city = "Mexico";    %tmp = "PlayerProfile.Player" @ "Western";
               case "Hollywood": %city = "Hollywood"; %tmp = "PlayerProfile.Player" @ "SciFi";
               case "Tokyo"    : %city = "Tokyo";     %tmp = "PlayerProfile.Player" @ "Monster";
               case "HongKong" : %city = "HongKong";  %tmp = "PlayerProfile.Player" @ "KungFu";
               case "Fiji"     : %city = "fiji";      %tmp = "PlayerProfile.Player" @ "Dinosaur";
            }
            %tmp2 = "%unlockedStars = " @ %tmp @ "StarsTake" @ $CurPlayerNum @ ";";      
            eval(%tmp2);      
            
            // Over clapperboards
            %rect = WorldMapGui.clapperPos[%city,%j];
            
            // Compensate widescreen offset
            %rect2 = GuiCenter.getPosition();
            
            if(%mouseX >= getWord(%rect,0)*%winScaleX + getWord(%rect2,0) && 
               %mouseX <= getWord(%rect,2)*%winScaleX + getWord(%rect2,0) &&
               %mouseY >= getWord(%rect,1)*%winScaleY + getWord(%rect2,1) && 
               %mouseY <= getWord(%rect,3)*%winScaleY + getWord(%rect2,1))
            {
//            if(%clap $= %obj.getName())
//            {               
               if(%unlockedTakes >= %j && getWord(%unlockedStars, %j-1) > 0)
               {
                  WorldMapGui.SetHidden(%clap,    true);
                  WorldMapGui.SetHidden(%clapf,   true);
                  WorldMapGui.SetHidden(%clapfr, false);
                  WorldMapGui.SetHidden(%clapr,   true);
                  WorldMapGui.SetHidden(%clapg,   true);                  
               }
               else
               if(%unlockedTakes >= %j)
               {
                  WorldMapGui.SetHidden(%clap,    true);
                  WorldMapGui.SetHidden(%clapf,   true);
                  WorldMapGui.SetHidden(%clapfr,  true);
                  WorldMapGui.SetHidden(%clapr,  false);
                  WorldMapGui.SetHidden(%clapg,   true);
               }
            }
            else
            {
               if(%unlockedTakes >= %j && getWord(%unlockedStars, %j-1) > 0)
               {                     
                  WorldMapGui.SetHidden(%clap,   true);
                  WorldMapGui.SetHidden(%clapf, false);
                  WorldMapGui.SetHidden(%clapfr, true);                  
                  WorldMapGui.SetHidden(%clapr,  true);
                  WorldMapGui.SetHidden(%clapg,  true);                  
               }
               else if(%unlockedTakes >= %j)
               {
                  WorldMapGui.SetHidden(%clap,   false);
                  WorldMapGui.SetHidden(%clapf,   true); 
                  WorldMapGui.SetHidden(%clapfr,  true);
                  WorldMapGui.SetHidden(%clapr,   true);
                  WorldMapGui.SetHidden(%clapg,   true);
               }               
               else
               {
                  WorldMapGui.SetHidden(%clap,    true);
                  WorldMapGui.SetHidden(%clapf,   true);
                  WorldMapGui.SetHidden(%clapfr,  true);
                  WorldMapGui.SetHidden(%clapr,   true);
                  WorldMapGui.SetHidden(%clapg,  false);                  
               }
            }
         }
         
         WorldMapGui.SetHidden(%bb,  false);
         WorldMapGui.SetHidden(%bbr, true);
         WorldMapGui.SetHidden(%bbp, true);
         
         if($WorldMapZoomedIn $= "Paris" && $CurFirstPlay $= 0)
         {
            WorldMapGui.SetHidden(%tut,  false);
            WorldMapGui.SetHidden(%tutr, true);
         }
      }
   }
}

function WMCamMouseHandler::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
   WorldMapGui.mouseDragging = true;
   
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   if(WorldMapGui.animatingFeedback $= true || WorldMapGui.unlockCity $= true)
      return;
   
   if(WorldMapGui.interpT > 0 && WorldMapGui.interpT < 1)
      return;
   
   WorldMapGui.canIPlaySound  = true;
   // Get mouse position
   %mouseX = getWord(%worldPosition,0);
   %mouseY = getWord(%worldPosition,1);  
      
   %obj = WMCam0.getObjectAt(%mouseX, %mouseY);
   if (%obj == 0)
      return;
      
   if(%obj.clickable)
   {
//      %pos3D = WMCam0.get3DPosAt(%mouseX, %mouseY);

      // Over cities
      if($WorldMapZoomedIn $= false &&
         (%obj.getName() $= "london_click_dummy" ||
         %obj.getName() $= "newyork_click_dummy" ||
         %obj.getName() $= "paris_click_dummy" ||
         %obj.getName() $= "mexico_click_dummy" ||
         %obj.getName() $= "hollywood_click_dummy" ||
         %obj.getName() $= "hongkong_click_dummy" ||
         %obj.getName() $= "tokyo_click_dummy" ||
         %obj.getName() $= "fiji_click_dummy" ))
      {			
         switch$(%obj.getName())
         {
            case "paris_click_dummy":     %i = 1; %objn = "Paris";
			   case "fiji_click_dummy":      %i = 2; %objn = "Fiji";
            case "london_click_dummy":    %i = 3; %objn = "London";            
            case "hongkong_click_dummy":  %i = 4; %objn = "HongKong";
            case "mexico_click_dummy":    %i = 5; %objn = "Mexico";
            case "tokyo_click_dummy":     %i = 6; %objn = "Tokyo";            
            case "newyork_click_dummy":   %i = 7; %objn = "NewYork";
            case "hollywood_click_dummy": %i = 8; %objn = "Hollywood";
         }
         if($CurPlayerUScene >= %i)
         {
             //play click sound only when not zoomed in.
             // Also stop the rotation sound. in case it was still playing.
             if($WorldMapZoomedIn $= false)
             {
                sfxStop(WorldMapGui.rotateSound);
                sfxPlay(SFX_CLICK);
             }
            
            WorldMapGui.selectScene(%objn, 0);
         }
         else
            ArcBall.onMouseDown(%mouseX, %mouseY);         
      }
      // Over clapperboards
      else
      {
         if($WorldMapZoomedIn $= "Paris" && 
            %obj.getName() $= "Tutorial_clapperboard" &&
            $CurFirstPlay $= 0)
         {
            cancelScheduleLCA(WorldMapGui.rotateID);
            
            // Restore the mouse cursor
            WorldMapGui.gameCtrl.delete();
            
            // Load selected scene
            sfxPlay(SFX_CLICK);
            WorldMapGui.loadedLevel = true;
            $CurTake = 1;
            $ReplayButtonPressed = true;
            $PlayTutorial = true;
            
            MainMenuGui.goHome();
            MainMenuGui.pushThread(loadlevel_menu_thread);
            return;            
         }
                  
         for(%j = 1; %j <= 4; %j++)
         {
            %clap  = $WorldMapZoomedIn @ "_take_" @ %j @ "_clapperboard";
            %clapr = $WorldMapZoomedIn @ "_take_" @ %j @ "_rollover";
            %clapg = $WorldMapZoomedIn @ "_take_" @ %j @ "_grayedout";
            
            switch$($WorldMapZoomedIn)
            {
               case "London"   : %city = "London";    %unlockedTakes = $CurPlayerMusicalUTake;
               case "NewYork"  : %city = "NewYork";   %unlockedTakes = $CurPlayerGangsterUTake;
               case "Paris"    : %city = "Paris";     %unlockedTakes = $CurPlayerSpyUTake;
               case "Mexico"   : %city = "Mexico";    %unlockedTakes = $CurPlayerWesternUTake;
               case "Hollywood": %city = "Hollywood"; %unlockedTakes = $CurPlayerSciFiUTake;
               case "Tokyo"    : %city = "Tokyo";     %unlockedTakes = $CurPlayerMonsterUTake;
               case "HongKong" : %city = "HongKong";  %unlockedTakes = $CurPlayerKungFuUTake;
               case "Fiji"     : %city = "Fiji";      %unlockedTakes = $CurPlayerDinosaurUTake;
            }
            
            // Over clapperboards
            %rect = WorldMapGui.clapperPos[%city,%j];

            // Compensate widescreen            
            %rect2 = GuiCenter.getPosition();
            
            if(%mouseX >= getWord(%rect,0)*%winScaleX + getWord(%rect2,0) && 
               %mouseX <= getWord(%rect,2)*%winScaleX + getWord(%rect2,0) &&
               %mouseY >= getWord(%rect,1)*%winScaleY + getWord(%rect2,1) && 
               %mouseY <= getWord(%rect,3)*%winScaleY + getWord(%rect2,1) &&
               WorldMapGui.loadedLevel $= false)
            {            
//            if(%clap $= %obj.getName() && WorldMapGui.loadedLevel $= false)
//            {               
               if(%unlockedTakes >= %j)
               {
                  cancelScheduleLCA(WorldMapGui.rotateID);
                  
                  // Restore the mouse cursor
                  WorldMapGui.gameCtrl.delete();
                  
                  // Load selected scene
				      sfxPlay(SFX_CLICK);
                  WorldMapGui.loadedLevel = true;
                  $CurTake = %j;
                  $ReplayButtonPressed = true;
                  
                  if($WorldMapZoomedIn $= "Paris" && $CurTake $= 1 && $CurFirstPlay $= 1)
                     $PlayTutorial = true;
                  
                  MainMenuGui.goHome();
                  MainMenuGui.pushThread(loadlevel_menu_thread);
                  return;
               }
            }
         }
      }
   }
   else
   {
      ArcBall.onMouseDown(%mouseX, %mouseY);
//    ArcBall.onMouseDown(%mouseX, getWord(GuiCenter.getExtent(),1)/2);
   }
}

// We use these functions to prevent the left-mouse button from sticking when it is
// released in the blurred border of the widescreen mode
function WMBackMainMenuButton::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
   $WorldGameGuiClicked = false;  
   
   // Avoid the mouse dragging to get stuck
   if(WorldMapGui.mouseDragging)
   {   
       WorldMapGui.canIPlaySound = false;
       WorldMapGui.mouseDragging = false;
       ArcBall.onMouseUp();
   }

//   WMCamMouseHandler.onMouseUp(%modifier, %worldPosition, %mouseClicks);
//   WMCamMouseHandler.onMouseDown(%modifier, %worldPosition, %mouseClicks);
}

function WorldMapGui::tutorialState2(%this)
{
   if(%this.WMTutorialState > 0)
   {
      WMTutorialBoxText.setText(%this.tutText2);//"To visit a set click on\nits location to zoom in.\nClick on Paris now to zoom in.");      
      %this.fadeInTutorial();
   }
   else
   {
      WMTutorialBox.setVisible(false);
      WMTutorialBoxText.setVisible(false);
   }
}

function WMBackMainMenuButton::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
//	sfxPlay(SFX_CLICK);
}

function WMBackButton::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
   sfxPlay(SFX_CLICK);
   sfxPlay(SFX_ZOOM);
      
   WorldMapGui.updateClapperboards(true);
      
   cancelScheduleLCA(WorldMapGui.rotateID);
   cancelScheduleLCA(WorldMapGui.zoomInID);
   WorldMapGui.interpT = 0;
      
   WorldMapGui.zoomOutSavedCameraTransform = Camera1.getTransform();
   WorldMapGui.onZoomOut(); 
}
/*
function WMStudioButton::onMouseEnter(%this)
{
   sfxPlay(SFX_OVER);   
}
*/

function WMStudioButtonDummyButton::onMouseMove(%this, %modifier, %worldPosition, %mouseClicks)
{
   WorldMapGui.hideCursor();
}

function WMStudioButton::onMouseMove(%this, %modifier, %worldPosition, %mouseClicks)
{
   WorldMapGui.hideCursor();
}

function WMStudioButton::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
   $WorldGameGuiClicked = false;   
      
   // Avoid the mouse dragging to get stuck
   if(WorldMapGui.mouseDragging)
   {
       WorldMapGui.canIPlaySound = false;      
       WorldMapGui.mouseDragging = false;
       ArcBall.onMouseUp();
   }   
}

function WMStudioButtonDummyButton::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
   $WorldGameGuiClicked = false;   
      
   // Avoid the mouse dragging to get stuck
   if(WorldMapGui.mouseDragging)
   {
       WorldMapGui.canIPlaySound = false;      
       WorldMapGui.mouseDragging = false;
       ArcBall.onMouseUp();
   }
/*   
   if(WorldMapGui.animatingFeedback $= false)
   {
      sfxPlay(AudioButtonPress); 
      $ReplayButtonPressed = true; 
      MainMenuGui.goHome(); 
      MainMenuGui.pushThread(award_room_thread);
   }
*/   
//   WMCamMouseHandler.onMouseUp(%modifier, %worldPosition, %mouseClicks);
}

//function WMStudioButton::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
//{
//   sfxPlay(SFX_CLICK);
//}
/*
function WMCamMouseHandlerW::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
   WMCamMouseHandler.onMouseUp(%modifier, %worldPosition, %mouseClicks);
}*/

function WMCamMouseHandler::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
   // End world map tutorial
   if(WorldMapGui.WMTutorialState $= 1)
   {
      WorldMapGui.WMTutorialState = 2;
      WorldMapGui.fadeOutTutorial();
      scheduleObjLCA(WorldMapGui, "HO", 750, "tutorialState2", 0);
   }   
   
   WorldMapGui.mouseDragging = false;
   $WorldGameGuiClicked = false;
   
   WorldMapGui.canIPlaySound = false;
   
   if(WorldMapGui.animatingFeedback $= true || WorldMapGui.unlockCity $= true)
      return;
      
//   ArcBall.onMouseUp();
}

/* //Unused
function WorldMapGui::checkRotationSound(%this,%sameAsPrev)
{   
   if (!%this.canIPlaySound || %sameAsPrev)
   {
	   %this.soundPlayingForMouse = false;
      sfxStop(%this.rotateSound);
   }
}*/

function WorldMapGui::checkMousePos(%this)
{         
   %curMousePos = canvas.getCursorPos();
   %mouseX = getWord(%curMousePos,0);
   %mouseY = getWord(%curMousePos,1);
   
   if($WorldMapZoomedIn !$= false)
   {
      // Compensate widescreen offset
      %rect2 = GuiCenter.getPosition();
      if(!$OnResumeDlg && !$OnExitDlg)
      {
         %this.gameCtrl.cursor.setPosition(
            %mouseX+1 - getWord(%rect2, 0), 
            %mouseY+1 - getWord(%rect2, 1));
      
         %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
         %this.gameCtrl.cursor.setVisible(true);
      }
      //WorldMapGui.hideCursor();  
   }

   // $WorldMapStartTime) < 5000  What this value means?? Changed to 2500 to avoid halts
   %obj = WMCam0.getObjectAt(%mouseX, %mouseY, (getSimTime() - $WorldMapStartTime) < 2500); 
   if(%obj !$= 0)
   {
      if(%obj.clickable)
      {
         if(%obj.getName() !$= "London" && %obj.getName() !$= "NewYork" && %obj.getName() !$= "Paris" && %obj.getName() !$= "Mexico" && 
            %obj.getName() !$= "Hollywood" && %obj.getName() !$= "Tokyo" && %obj.getName() !$= "HongKong" && %obj.getName() !$= "Fiji")
         {
            $WorldGameGuiHoverCity = true;               
         }
         else
            $WorldGameGuiHoverCity = false;
         
         if(WorldMapGui.overObj !$= %obj)
         {
            if ($WorldGameGuiHoverCity $= true)
            {
               if (%obj.getName() !$= "London" && %obj.getName() !$= "NewYork" && %obj.getName() !$= "Paris" && %obj.getName() !$= "Mexico" && 
                   %obj.getName() !$= "Hollywood" && %obj.getName() !$= "Tokyo" && %obj.getName() !$= "HongKong" && %obj.getName() !$= "Fiji")
               {
                  sfxPlay(SFX_OVER);
                  WorldMapGui.overObj = %obj;
               }
               else
                  WorldMapGui.overObj = "";
            }
            else
            {
               sfxPlay(SFX_OVER);
               WorldMapGui.overObj = %obj;
            }
         }
                  
         if($WorldMapZoomedIn $= false)
         {
            if ($WorldGameGuiHoverCity $= true)
            {
               if (%obj.getName() !$= "London" && %obj.getName() !$= "NewYork" && %obj.getName() !$= "Paris" && %obj.getName() !$= "Mexico" && 
                   %obj.getName() !$= "Hollywood" && %obj.getName() !$= "Tokyo" && %obj.getName() !$= "HongKong" && %obj.getName() !$= "Fiji")
               {
                  switch$(%obj.getName())
                  {
                     case "paris_click_dummy":     %i = 1;
                     case "fiji_click_dummy":      %i = 2;                     
                     case "london_click_dummy":    %i = 3;
                     case "hongkong_click_dummy":  %i = 4;
                     case "mexico_click_dummy":    %i = 5;
                     case "tokyo_click_dummy":     %i = 6;
                     case "newyork_click_dummy":   %i = 7;
                     case "hollywood_click_dummy": %i = 8;
                  }
                  if($CurPlayerUScene < %i)
                  {
                     %this.showPadlock = true;
                     if(!$OnResumeDlg && !$OnExitDlg)
                        %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/padlock");
                  }
                  else
                     %this.showPadlock = false;               
               }
               else
                  %this.showPadlock = false;
            }
            else
               %this.showPadlock = false;
         }
      }
      else
      {
         $WorldGameGuiHoverCity = false;
         WorldMapGui.overObj = "";
         %this.showPadlock = false;
      }
   }
   
   %this.checkMousePosID = scheduleObjLCA(%this, "HO", 30, "checkMousePos", 0);   
}

function WorldMapGui::onRotate(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);   
   
   %curMousePos = canvas.getCursorPos();
   %mouseX = getWord(%curMousePos,0);
   %mouseY = getWord(%curMousePos,1); 
          
   if(%mouseY > 460*%winScaleY)
   {
      $WorldMapGuiBelow460 = true;
//      %this.gameCtrl.cursor.setVisible(false);
//      Canvas.showCursor();
      //WorldMapGui.hideCursor();
   }
   else
   {
      $WorldMapGuiBelow460 = false;
      
      if($WorldGameGuiHoverCity !$= true && $WorldMapZoomedIn $= false)
      {
         if(!WorldMapGui.showPadlock)
         {
            if(!$OnResumeDlg && !$OnExitDlg)
            {
               if($WorldGameGuiClicked $= true)
                  %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");
               else
                  %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
            }
         }
         //WorldMapGui.hideCursor();
      }
      else
      {
         if(!$OnResumeDlg && !$OnExitDlg)
         {
            if(WorldMapGui.showPadlock)
               %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/padlock");
            else
               %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
         }
         //WorldMapGui.hideCursor();
//         %this.gameCtrl.cursor.setVisible(false);
//         Canvas.showCursor();
      }      
   }
   
   %prevX = getWord(%this.mousePosForDrag,0);
   %prevY = getWord(%this.mousePosForDrag,1); 
   %sameAsPrev = (%mouseX $= %prevX) && (%mouseY $= %prevY);
   %this.mousePosForDrag = %curMousePos;
   //%this.checkRotationSound(%sameAsPrev);
   
   if (%this.canIPlaySound && !%sameAsPrev)
   {
       if (!%this.soundPlayingForMouse)
	   {
			%this.turnDelayMouse = 0;
	       %this.rotateSound = sfxPlay(SFX_ROLL);
	       %this.soundPlayingForMouse = true;
	   } 
   }
   else
   {
		if (%this.turnDelayMouse ++ > 4)
		{
		   %this.soundPlayingForMouse = false;
		   if (!%this.soundPlayingForKeyb)
			  sfxStop(%this.rotateSound);
		}
   }
   
//   %this.globeRotation = 0.02;
//   Camera1.rotateAroundGlobe(%this.globeRotation);
   if(%this.keyPressed $= false)
   {
      if(!$OnResumeDlg && !$OnExitDlg)
      {
         if(!WorldMapGui.showPadlock)
         {
            if($WorldGameGuiClicked $= true)
               %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_clicked");
            else if($WorldMapGuiBelow460 $= true)
               %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
            else if($WorldGameGuiHoverCity $= false)
               %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor");
         }

         // Compensate widescreen offset
         %rect2 = GuiCenter.getPosition();
         %this.gameCtrl.cursor.setPosition(%mouseX+1 - getWord(%rect2,0), %mouseY+1 - getWord(%rect2,1));
         ArcBall.onMouseMove(%mouseX, %mouseY, Camera1);
      }
   }
   
   %this.rotateID = scheduleObjLCA(%this, "HO", 100, "onRotate", 0);
}

function WorldMapGui::AnimateClouds(%this)
{
   %transf = Clouds.getTransform();
   
   %this.animateCloudRotation += 0.005;
   if(%this.animateCloudRotation > 6.2831)
      %this.animateCloudRotation = 0;
           
   %transfNew = getWord(%transf, 0) SPC getWord(%transf, 1) SPC getWord(%transf, 2) SPC "0 0 1" SPC %this.animateCloudRotation;
                
   Clouds.setTransform(%transfNew);
   
   %this.animateCloudID = %this.schedule(100, "AnimateClouds");
}

// Use for quickly hiding TSStatic
function WorldMapGui::SetHidden(%this, %id, %val)
{ 
   if(isObject(%id))
   {
      %ghost_id = $ClientConnection.getGhostID(%id);  
      %client_id = ServerConnection.resolveGhostID(%ghost_id);  
      %client_id.SetHidden(%val);
   }
}

function WorldMapGui::selectScene(%this, %obj, %t)
{
   if($WorldMapZoomedIn $= false || %t > 0)
   {
      cancelScheduleLCA(%this.rotateID);
      cancelScheduleLCA(%this.zoomInID);
      %this.initialCameraTransform = Camera1.getTransform();      
   }
   else
   {
//      %this.savedCameraTransform = %this.initialCameraTransform;
      %this.hideAll();      
   }
   
   %this.interpT = %t;
   %this.savedCameraTransform = Camera1.getTransform();

   $WorldMapZoomedIn = %obj.getName();
   
   switch$($WorldMapZoomedIn)
   {
      case "London"   : $CurSceneName = "MusicalLevel";
      case "NewYork"  : $CurSceneName = "GangsterLevel";
      case "Paris"    : $CurSceneName = "SpyLevel";
      case "Mexico"   : $CurSceneName = "WesternLevel";
      case "Hollywood": $CurSceneName = "SciFiLevel";
      case "Tokyo"    : $CurSceneName = "MonsterLevel";
      case "HongKong" : $CurSceneName = "KungFuLevel";
      case "Fiji"     : $CurSceneName = "DinosaurLevel";
   }
   sfxPlay(SFX_ZOOM);
   
   %this.onZoomIn(%obj);
}

function WorldMapGui::StarPopEffect(%this, %position)
{
   %this.particleCounter++;
   
   new ParticleEmitterNode(ParticleCloud @ %this.particleCounter) 
   {
      canSaveDynamicFields = "1";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "WMSparkEmitterNode";
      emitter = "WMSparkEmitter";
      velocity = "1";
   };
   
   %obj = ParticleCloud @ %this.particleCounter;

   %obj.position = %position;
   if(isObject(%obj))
      ParticleEffects.add(%obj);
   scheduleObjLCA(%this, "HO", 5000, "onKillParticle", 1, %obj);
}

function WorldMapGui::onKillParticle(%this, %obj)
{
   if(isObject(%obj))
   {
      ParticleEffects.remove(%obj);
      %obj.delete();
   }
}

function WorldMapGui::showStarsGained(%this, %take)
{
//   $LastStarsInTake = 3;
//   $CurPlayerStars = 31;
//   $StarsWonInTake = 2;

   // Animation speeed
   %this.aniSpeed = 0.5;

   if($StarsWonInTake $= 0)
      return false;
      
   WMBackButton.setVisible(false);
   //WMStudioButton.setVisible(false);      

   %numStars = $CurPlayerStars - $StarsWonInTake;
//   if(%numStars $= 10 || %numStars $= 30 || %numStars $= 50)
//      %this.updateAwards(%numStars+1, false);
//   else   
      %this.updateAwards(%numStars, true);
         
   %city = $WorldMapZoomedIn;
   
   // Position (city, take [1-4], star [1-5])
   %pos["London","1","1"] = "199 195";
   %pos["London","1","2"] = "225 192";
   %pos["London","1","3"] = "248 183";
   %pos["London","1","4"] = "272 186";
   %pos["London","1","5"] = "297 181";

   %pos["London","2","1"] = "273 97";
   %pos["London","2","2"] = "300 100";
   %pos["London","2","3"] = "324 93";
   %pos["London","2","4"] = "348 100";
   %pos["London","2","5"] = "373 99";
   
   %pos["London","3","1"] = "471 113";
   %pos["London","3","2"] = "496 119";
   %pos["London","3","3"] = "521 116";
   %pos["London","3","4"] = "544 127";
   %pos["London","3","5"] = "568 129";

   %pos["London","4","1"] = "477 226";
   %pos["London","4","2"] = "501 235";
   %pos["London","4","3"] = "525 235";
   %pos["London","4","4"] = "546 249";
   %pos["London","4","5"] = "570 255";

   %pos["NewYork","1","1"] = "165 241";
   %pos["NewYork","1","2"] = "190 236";
   %pos["NewYork","1","3"] = "211 224";
   %pos["NewYork","1","4"] = "236 225";
   %pos["NewYork","1","5"] = "261 217";

   %pos["NewYork","2","1"] = "240 68";
   %pos["NewYork","2","2"] = "266 68";
   %pos["NewYork","2","3"] = "287 59";
   %pos["NewYork","2","4"] = "312 65";
   %pos["NewYork","2","5"] = "333 60";
   
   %pos["NewYork","3","1"] = "448 96";
   %pos["NewYork","3","2"] = "473 99";
   %pos["NewYork","3","3"] = "496 94";
   %pos["NewYork","3","4"] = "518 102";
   %pos["NewYork","3","5"] = "543 102";

   %pos["NewYork","4","1"] = "471 197";
   %pos["NewYork","4","2"] = "499 205";
   %pos["NewYork","4","3"] = "528 203";
   %pos["NewYork","4","4"] = "553 215";
   %pos["NewYork","4","5"] = "582 219";
   
   %pos["Paris","1","1"] = "236 262";
   %pos["Paris","1","2"] = "262 256";
   %pos["Paris","1","3"] = "282 240";
   %pos["Paris","1","4"] = "307 240";
   %pos["Paris","1","5"] = "329 229";

   %pos["Paris","2","1"] = "242 150";
   %pos["Paris","2","2"] = "270 148";
   %pos["Paris","2","3"] = "297 139";
   %pos["Paris","2","4"] = "323 143";
   %pos["Paris","2","5"] = "350 138";
   
   %pos["Paris","3","1"] = "409 124";
   %pos["Paris","3","2"] = "435 129";
   %pos["Paris","3","3"] = "461 125";
   %pos["Paris","3","4"] = "486 136";
   %pos["Paris","3","5"] = "513 136";

   %pos["Paris","4","1"] = "433 226";
   %pos["Paris","4","2"] = "461 230";
   %pos["Paris","4","3"] = "487 225";
   %pos["Paris","4","4"] = "511 235";
   %pos["Paris","4","5"] = "537 235";

   %pos["Mexico","1","1"] = "214 340";
   %pos["Mexico","1","2"] = "245 342";
   %pos["Mexico","1","3"] = "271 335";
   %pos["Mexico","1","4"] = "298 341";
   %pos["Mexico","1","5"] = "326 341";

   %pos["Mexico","2","1"] = "237 192";
   %pos["Mexico","2","2"] = "264 186";
   %pos["Mexico","2","3"] = "287 174";
   %pos["Mexico","2","4"] = "315 173";
   %pos["Mexico","2","5"] = "342 163";
   
   %pos["Mexico","3","1"] = "453 177";
   %pos["Mexico","3","2"] = "480 186";
   %pos["Mexico","3","3"] = "507 186";
   %pos["Mexico","3","4"] = "529 197";
   %pos["Mexico","3","5"] = "554 202";

   %pos["Mexico","4","1"] = "482 276";
   %pos["Mexico","4","2"] = "507 290";
   %pos["Mexico","4","3"] = "534 294";
   %pos["Mexico","4","4"] = "555 310";
   %pos["Mexico","4","5"] = "580 319";

   %pos["Hollywood","1","1"] = "163 258";
   %pos["Hollywood","1","2"] = "194 251";
   %pos["Hollywood","1","3"] = "220 234";
   %pos["Hollywood","1","4"] = "251 234";
   %pos["Hollywood","1","5"] = "278 222";

   %pos["Hollywood","2","1"] = "123 110";
   %pos["Hollywood","2","2"] = "151 113";
   %pos["Hollywood","2","3"] = "179 107";
   %pos["Hollywood","2","4"] = "204 115";
   %pos["Hollywood","2","5"] = "232 116";
   
   %pos["Hollywood","3","1"] = "573 112";
   %pos["Hollywood","3","2"] = "602 118";
   %pos["Hollywood","3","3"] = "630 114";
   %pos["Hollywood","3","4"] = "655 124";
   %pos["Hollywood","3","5"] = "682 124";

   %pos["Hollywood","4","1"] = "558 226";
   %pos["Hollywood","4","2"] = "583 230";
   %pos["Hollywood","4","3"] = "609 225";
   %pos["Hollywood","4","4"] = "630 234";
   %pos["Hollywood","4","5"] = "654 234";

   %pos["Tokyo","1","1"] = "200 254";
   %pos["Tokyo","1","2"] = "224 252";
   %pos["Tokyo","1","3"] = "245 244";
   %pos["Tokyo","1","4"] = "268 246";
   %pos["Tokyo","1","5"] = "292 241";

   %pos["Tokyo","2","1"] = "178 153";
   %pos["Tokyo","2","2"] = "200 151";
   %pos["Tokyo","2","3"] = "222 142";
   %pos["Tokyo","2","4"] = "243 144";
   %pos["Tokyo","2","5"] = "267 139";
   
   %pos["Tokyo","3","1"] = "302 97";
   %pos["Tokyo","3","2"] = "326 96";
   %pos["Tokyo","3","3"] = "348 89";
   %pos["Tokyo","3","4"] = "371 93";
   %pos["Tokyo","3","5"] = "397 91";

   %pos["Tokyo","4","1"] = "411 170";
   %pos["Tokyo","4","2"] = "435 170";
   %pos["Tokyo","4","3"] = "456 164";
   %pos["Tokyo","4","4"] = "478 170";
   %pos["Tokyo","4","5"] = "500 168";

   %pos["HongKong","1","1"] = "204 215";
   %pos["HongKong","1","2"] = "231 210";
   %pos["HongKong","1","3"] = "253 198";
   %pos["HongKong","1","4"] = "279 199";
   %pos["HongKong","1","5"] = "305 191";

   %pos["HongKong","2","1"] = "224 108";
   %pos["HongKong","2","2"] = "249 106";
   %pos["HongKong","2","3"] = "271 98";
   %pos["HongKong","2","4"] = "295 102";
   %pos["HongKong","2","5"] = "320 99";
   
   %pos["HongKong","3","1"] = "423 88";
   %pos["HongKong","3","2"] = "447 90";
   %pos["HongKong","3","3"] = "470 85";
   %pos["HongKong","3","4"] = "493 91";
   %pos["HongKong","3","5"] = "518 90";

   %pos["HongKong","4","1"] = "499 155";
   %pos["HongKong","4","2"] = "528 162";
   %pos["HongKong","4","3"] = "556 159";
   %pos["HongKong","4","4"] = "583 171";
   %pos["HongKong","4","5"] = "614 174";

   %pos["Fiji","1","1"] = "172 264";
   %pos["Fiji","1","2"] = "205 264";
   %pos["Fiji","1","3"] = "235 255";
   %pos["Fiji","1","4"] = "264 259";
   %pos["Fiji","1","5"] = "297 256";

   %pos["Fiji","2","1"] = "301 91";
   %pos["Fiji","2","2"] = "325 100";
   %pos["Fiji","2","3"] = "350 102";
   %pos["Fiji","2","4"] = "370 116";
   %pos["Fiji","2","5"] = "393 122";
   
   %pos["Fiji","3","1"] = "494 117";
   %pos["Fiji","3","2"] = "516 120";
   %pos["Fiji","3","3"] = "539 118";
   %pos["Fiji","3","4"] = "559 126";
   %pos["Fiji","3","5"] = "581 127";

   %pos["Fiji","4","1"] = "472 211";
   %pos["Fiji","4","2"] = "492 220";
   %pos["Fiji","4","3"] = "515 221";
   %pos["Fiji","4","4"] = "534 234";
   %pos["Fiji","4","5"] = "557 240";

   // Get number of stars   
   switch$(%city)
   {
      case "London"   : %tmp = "PlayerProfile.Player" @ "Musical";
      case "NewYork"  : %tmp = "PlayerProfile.Player" @ "Gangster";
      case "Paris"    : %tmp = "PlayerProfile.Player" @ "Spy";
      case "Mexico"   : %tmp = "PlayerProfile.Player" @ "Western";
      case "Hollywood": %tmp = "PlayerProfile.Player" @ "SciFi";
      case "Tokyo"    : %tmp = "PlayerProfile.Player" @ "Monster";
      case "HongKong" : %tmp = "PlayerProfile.Player" @ "KungFu";
      case "Fiji"     : %tmp = "PlayerProfile.Player" @ "Dinosaur";
   }
   %tmp2 = "%unlockedStars = " @ %tmp @ "StarsTake" @ $CurPlayerNum @ ";";      
   eval(%tmp2); 
      
   // All stars are initially gray, except the stars already gained
   for(%k = 1; %k <= 5; %k++)
   {
      %obj1 = %city @ "_take_" @ %take @ "_star_" @ %k @ "_grayedout";      
      %obj2 = %city @ "_take_" @ %take @ "_star_" @ %k;
            
      if(%k <= $LastStarsInTake)
      {
         %this.SetHidden(%obj1, true);
         %this.SetHidden(%obj2, false);         
      }
      else
      {
         %this.SetHidden(%obj1, false);
         %this.SetHidden(%obj2, true);
      }
   }
   
   // Animate each star gained
   %triggerTime = 0;
   for(%i = $LastStarsInTake+1; %i <= $LastStarsInTake+$StarsWonInTake; %i++)
   {
      %this.animatingFeedback = true;
      
      %x = getWord(%pos[%city,%take,%i],0);
      %y = getWord(%pos[%city,%take,%i],1);
      scheduleObjLCA(%this, "HO", %triggerTime, "showStarsGained2", 5, %x, %y, %city, %take, %i);
      
      %numStars = $CurPlayerStars - $StarsWonInTake + (%i - $LastStarsInTake);

//      if(%numStars $= 10 || %numStars $= 30 || %numStars $= 50)   
//         %triggerTime += 900;
      
      %triggerTime += 2000 * %this.aniSpeed;
   }
   
   scheduleObjLCA(%this, "HO", %triggerTime, "showStarsGained9", 0);
      
   return true;
}

// Show star and pulse it (grow stage) at clapperboard
function WorldMapGui::showStarsGained2(%this, %x, %y, %city, %take, %star)
{
	sfxPlay(SFX_STARGAIN);
	sfxPlay(SFX_STARMOVE);
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   // Add pop star
   %tmp = ("StarPop_" @ %take @ "_" @ %star);
   if(isObject(%tmp))
      %tmp.delete();
      
   %popStar = new GuiPlasticBitmapCtrl(%tmp) 
   {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      HorizSizing = "relative";
      VertSizing = "relative";
      Extent = "68 68";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      wrap = "0";
      is3D = "0";
      Interval = "0";
      DML = "scriptsAndAssets/data/ui/menu/map/star.png";
      rotation = "0";
      deltaRotation = "0";
      noClip = "0";
      aniTime = "0";
   };
//   %popStar.setPosition((%x-33) * %winScaleX, (%y-33) * %winScaleY);
   %popStar.setPosition(%x*%winScaleX - 33, %y*%winScaleY - 33);
   WMAnimatedStar.add(%popStar);
   %popStar.setVisible(true);
   
   %origPX = getWord(%popStar.getPosition(), 0);
   %origPY = getWord(%popStar.getPosition(), 1);
   %origEX = getWord(%popStar.getExtent(), 0);
   %origEY = getWord(%popStar.getExtent(), 1);
   
   %extX = getWord(%popStar.getExtent(),   0) * 1.9;
   %extY = getWord(%popStar.getExtent(),   1) * 1.9;
   %posX = getWord(%popStar.getPosition(), 0) - ((%extX/2) - (getWord(%popStar.getExtent(), 0)/2));
   %posY = getWord(%popStar.getPosition(), 1) - ((%extY/2) - (getWord(%popStar.getExtent(), 1)/2));

   // Grow
   %popStar.animateBounds(%posX, %posY, %extX, %extY, 0, 250 * %this.aniSpeed, "1 2");
   
   scheduleObjLCA(%this, "HO", 250 * %this.aniSpeed, "showStarsGained3", 6, %popStar, %origPX, %origPY, %origEX, %origEY, %star);
   
   // Particle effect (explosion)
   ParticleFx.ScoreFx((%x+18)*%winScaleX, (%y+18)*%winScaleY, 2 * %this.aniSpeed, 1.8);
   
   // Show lit star
   %obj = %city @ "_take_" @ %take @ "_star_" @ %star @ "_grayedout";
   %this.SetHidden(%obj, true);
   %obj = %city @ "_take_" @ %take @ "_star_" @ %star;
   %this.SetHidden(%obj, false);
}

// Shrink when star is still at the clapperboard
function WorldMapGui::showStarsGained3(%this, %popStar, %origPX, %origPY, %origEX, %origEY, %star)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   // Shrink
   %popStar.animateBounds(%origPX, %origPY, %origEX, %origEY, 0, 250 * %this.aniSpeed, "2 2");
   
   scheduleObjLCA(%this, "HO", 250 * %this.aniSpeed, "showStarsGained4", 2, %popStar, %star);
}

// Star animates from clapperboard to awards
function WorldMapGui::showStarsGained4(%this, %popStar, %star)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
//   %curStar = %star - $LastStarsInTake;
//   %curStar += ($CurPlayerStars - $StarsWonInTake);
   
   %origPX = getWord(%popStar.getPosition(), 0);
   %origPY = getWord(%popStar.getPosition(), 1);   
   
//   if(%curStar > 10 && %curStar <= 30) %curStar -= 10;
//   else if(%curStar > 30 && %curStar <= 50) %curStar -= 30;
//   else if(%curStar > 50 && %curStar <= 70) %curStar -= 50;
//   else if(%curStar > 70) %curStar = 0;
   
   // Destination position of the star in the awards
   %posStar = "86 515";   
//   %posStar[0]  = "23 542"; %posStar[1]  = "48 538"; %posStar[2]  = "73 544"; %posStar[3]  = "99 538"; %posStar[4]  = "124 544";   
//   %posStar[5]  = "23 512"; %posStar[6]  = "48 508"; %posStar[7]  = "73 514"; %posStar[8]  = "99 508"; %posStar[9]  = "124 514";
//   %posStar[10] = "23 482"; %posStar[11] = "48 478"; %posStar[12] = "73 484"; %posStar[13] = "99 478"; %posStar[14] = "124 484";
//   %posStar[15] = "23 452"; %posStar[16] = "48 448"; %posStar[17] = "73 454"; %posStar[18] = "99 448"; %posStar[19] = "124 454";
   
//   if(%curStar > 0)
//   {
//      %x = getWord(%posStar[%curStar-1], 0);
//      %y = getWord(%posStar[%curStar-1], 1);
      %x = getWord(%posStar, 0);
      %y = getWord(%posStar, 1);
//   }
//   else
//   {
//      %x = 71;
//      %y = 410;
//   }
   
   %extX = getWord(%popStar.getExtent(), 0);
   %extY = getWord(%popStar.getExtent(), 1);
   
//   %popStar.deltaRotation = "-220";
   %popStar.animateBounds(%x*%winScaleX - 33, %y*%winScaleY - 30, 
                          %extX, %extY, 0, 1000 * %this.aniSpeed, "0 0"); // 1 2
   
   ParticleFx.CometGenericFx((%origPX+33), (%origPY+33), %x*%winScaleX, %y*%winScaleY, 1 * %this.aniSpeed, 2);
   
   // Start spinning
   %popStar.starRotateStop = false;
   %popStar.rotation = 0;
   scheduleObjLCA(%this, "HO", 50 * %this.aniSpeed, "popStarRotate", 2, %popStar, 360 / 18);
      
   // Stop spinning
   scheduleObjLCA(%this, "HO", 800 * %this.aniSpeed, "popStarRotateStop", 1, %popStar);         
   
   scheduleObjLCA(%this, "HO", 1050 * %this.aniSpeed, "showStarsGained5", 2, %popStar, %star);   
}

// Star arrived at the awards
function WorldMapGui::showStarsGained5(%this, %popStar, %star)
{  
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %x = getWord(%popStar.getPosition(), 0);
   %y = getWord(%popStar.getPosition(), 1);
   
   // Particle effect (explosion)
   ParticleFx.ScoreFx(%x+(48*%winScaleX), %y+(43*%winScaleY), 2 * %this.aniSpeed, 1.8);
   %origPX = getWord(%popStar.getPosition(), 0);
   %origPY = getWord(%popStar.getPosition(), 1);
   %origEX = getWord(%popStar.getExtent(), 0);
   %origEY = getWord(%popStar.getExtent(), 1);
   
   %extX = getWord(%popStar.getExtent(),   0) * 1.9;
   %extY = getWord(%popStar.getExtent(),   1) * 1.9;
   %posX = getWord(%popStar.getPosition(), 0) - ((%extX/2) - (getWord(%popStar.getExtent(), 0)/2));
   %posY = getWord(%popStar.getPosition(), 1) - ((%extY/2) - (getWord(%popStar.getExtent(), 1)/2));

   // Grow
   %popStar.animateBounds(%posX, %posY, %extX, %extY, 0, 250 * %this.aniSpeed, "1 2");
   
   scheduleObjLCA(%this, "HO", 250 * %this.aniSpeed, "showStarsGained6", 6, %popStar, %origPX, %origPY, %origEX, %origEY, %star);   
}

// Shrink when star is at the awards
function WorldMapGui::showStarsGained6(%this, %popStar, %origPX, %origPY, %origEX, %origEY, %star)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   // Shrink
   %popStar.animateBounds(%origPX, %origPY, %origEX, %origEY, 0, 250 * %this.aniSpeed, "2 2");
   
   scheduleObjLCA(%this, "HO", 250 * %this.aniSpeed, "showStarsGained7", 2, %popStar, %star);
}

// Star disappears
function WorldMapGui::showStarsGained7(%this, %popStar, %star)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   if($StarsWonInTake > 0 || $LastStarsInTake > 0)
      %numStars = $CurPlayerStars - $StarsWonInTake + (%star - $LastStarsInTake);
   else
      %numStars = $CurPlayerStars;
   sfxPlay(SFX_STARGAIN);  
   %popStar.animateAlpha(0, 0, 250 * %this.aniSpeed, "0 0");
   %this.updateAwards(%numStars, true);         
/*
   if(%numStars $= 10 || %numStars $= 30 || %numStars $= 50)   
   {
      switch$(%numStars)
      {
      case 10: %x = 72; %y = 470;
      case 30: %x = 70; %y = 411;
      case 50: %x = 70; %y = 411;
      }
      
      %x = 87;
      %y = 397;
      
      // Particle effect (explosion)
      ParticleFx.ScoreFx((%x+18)*%winScaleX, (%y+18)*%winScaleY, 2, 1.8);
      
      scheduleObjLCA(%this, "HO", 900, "showStarsGained7dot5", 3, %popStar, %star, true); 
   }
   else */
//   {
      %this.showStarsGained7dot5(%popStar, %star, false);
//   }
}

function WorldMapGui::showStarsGained7dot5(%this, %popStar, %star, %goToNextStar)
{
   if(%goToNextStar && ($StarsWonInTake - (%star - $LastStarsInTake)) > 0)
   {
      %numStars = $CurPlayerStars - $StarsWonInTake + (%star - $LastStarsInTake);      
//      %this.updateAwards(%numStars+1, false);
      %this.updateAwards(%numStars, false);
   }

   scheduleObjLCA(%this, "HO", 250 * %this.aniSpeed, "showStarsGained8", 1, %popStar);   
}

// Delete star object
function WorldMapGui::showStarsGained8(%this, %popStar)
{
   %popStar.delete();
}

// End of all animations
function WorldMapGui::showStarsGained9(%this)
{
   $StarsWonInTake = 0;
   $LastStarsInTake = 0;
   
//$CurPlayerStars - $StarsWonInTake   
   %this.showUnlockedScenes();
   
   //WMStudioButton.setVisible(true);
}

// Rotate the star while it spins
function WorldMapGui::popStarRotate(%this, %obj, %speed)
{
   %newRotation = (%obj.rotation + %speed) % 360;
   %obj.rotation = %newRotation;

   if(%obj.starRotateStop)
   {
      if(%newRotation $= 0)
      {
         %obj.starRotateStop = false;
         return;
      }
   }
      
   scheduleObjLCA(%this, "HO", 50, "popStarRotate", 2, %obj, %speed);   
}

// Stop star rotation
function WorldMapGui::popStarRotateStop(%this, %obj)
{
   %obj.starRotateStop = true;
}

// Visual feedback for the recently unlocked scenes
function WorldMapGui::showUnlockedScenes(%this)
{
   // Show feedback of recently unlocked scenes?
   if($SceneJustUnlocked $= true)
      $SceneJustUnlocked = false;
   else
   {
      %this.animatingFeedback = false;
      WMBackButton.setVisible(true);      
      return;
   }
  
  // TODO 
   %this.unlockCity = true;
      
//   $LastUnlockedScene = 1;
//   $CurUnlockedScene = 2;

   %cities[1] = "Paris"; 
   %cities[2] = "Fiji";
   %cities[3] = "London";
   %cities[4] = "HongKong";   
   %cities[5] = "Mexico";   
   %cities[6] = "Tokyo";
   %cities[7] = "NewYork";
   %cities[8] = "Hollywood";
      
   for(%i = $LastUnlockedScene+1; %i <= $CurUnlockedScene; %i++)
   {
      %text = "";
      switch$(%i)
      {
         case 1: %text = "Paris";
		   case 2: %text = "Fiji";
         case 3: %text = "London";
         case 4: %text = "Hong Kong";
         case 5: %text = "Mexico";
         case 6: %text = "Tokyo";
         case 7: %text = "New York";
         case 8: %text = "Hollywood";
      }
      %text = "   " @ %text SPC "unlocked!" @ "   ";
      
      scheduleObjLCA(%this, "HO", %scheduleTime, "showUnlockedScenes2", 2, %text, %i);
      %scheduleTime += 3100;
   }
   
   // Go to last city
   // TODO
   scheduleObjLCA(%this, "HO", %scheduleTime, "toggleCity", 1, %i-1);   
}

function WorldMapGui::showUnlockedScenes2(%this, %text, %textIdx)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %obj  = WMUnlockedSceneText;
   %objs = WMUnlockedSceneTextShadow;
   
   %obj.setAlpha(0);
   %objs.setAlpha(0);
   
   %obj.setText(%text);
   %objs.setText(%text);
   
   %obj.setVisible(true);
   %objs.setVisible(true);
   
   %width = 800;
   %height = 150;
   %posx = 400;
   %posy = 25;
   
   %obj.animateAlpha(1, 0, 500, "0 0");
   %objs.animateAlpha(1, 0, 500, "0 0");
   
   %obj.setPosition(%posx * %winScaleX, (300-%posy) * %winScaleY);
   %obj.setExtent((%width-(%posx*2)) * %winScaleX, (%height-(%posy*2)) * %winScaleY);
   %obj.animateBounds(0 * %winScaleX, (300-(%height/2))*%winScaleY, %width*%winScaleX, %height*%winScaleY, 0, 500, "1 2");   

   %objs.setPosition((%posx+3) * %winScaleX, (303-%posy) * %winScaleY);
   %objs.setExtent((%width-(%posx*2)) * %winScaleX, (%height-(%posy*2)) * %winScaleY);
   %objs.animateBounds(3 * %winScaleX, (303-(%height/2))*%winScaleY, %width*%winScaleX, %height*%winScaleY, 0, 500, "1 2");   

   scheduleObjLCA(%this, "HO", 2000, "showUnlockedScenes3", 1, %textIdx);
}

function WorldMapGui::showUnlockedScenes3(%this, %textIdx)
{
   %obj  = WMUnlockedSceneText;
   %objs = WMUnlockedSceneTextShadow;
   
   %obj.animateAlpha(0, 0, 1000, "0 0");
   %objs.animateAlpha(0, 0, 1000, "0 0");
   
   scheduleObjLCA(%this, "HO", 1000, "showUnlockedScenes4", 1, %textIdx);   
}

function WorldMapGui::showUnlockedScenes4(%this, %textIdx)
{
   %obj  = WMUnlockedSceneText;
   %objs = WMUnlockedSceneTextShadow;
   
   %obj.setVisible(false);
   %objs.setVisible(false);
   
   // TODO
//   WorldMapGui.toggleCity(%textIdx);
//   %this.tabHit = false;         
//   %this.unlockCity = false;
}

// Toggle city (go to %cityIdx)
function WorldMapGui::toggleCity(%this, %cityIdx)
{
   // This is to prevent the user from pressing TAB
   %this.tabHit = true;
   %this.zoomOutAfterTab = true;
   
   // This is to make sure the city doesn't pop out
   $SceneJustUnlocked = true;
   
   switch$(%cityIdx)
   {
      case 1: %city = "Paris";
	   case 2: %city = "Fiji";
      case 3: %city = "London";
      case 4: %city = "HongKong";
      case 5: %city = "Mexico";
      case 6: %city = "Tokyo";
      case 7: %city = "NewYork";
      case 8: %city = "Hollywood";
   }
         
   // Change viewpoint to next city
   %this.selectScene(%city, 0);        
}

// Called when the players hits TAB
function WorldMapGui::toggleCityByKeyboard(%this)
{
   if(%this.tabHit $= true)
      return;

   $WorldGameGuiHoverCity = true;
   
//   %this.cursor.setVisible(false);
//   lockMouse(false);
//   Canvas.showCursor();   
   if(!$OnResumeDlg && !$OnExitDlg)
      %this.gameCtrl.cursor.setBitmap("scriptsAndAssets/data/ui/minigame/hand_cursor_point");
   //WorldMapGui.hideCursor();
   
   // This is to prevent the user from pressing the TAB key twice too fast
   %this.tabHit = true;
   
   %this.zoomOutAfterTab = true;
   
   // Don't toggle if camera is during animation
   if(isEventPending(%this.zoomInID) || isEventPending(%this.zoomOutID))
      return;
      
   %cities[0] = "Paris"; 
   %cities[1] = "Fiji";
   %cities[2] = "London";
   %cities[3] = "HongKong";   
   %cities[4] = "Mexico";   
   %cities[5] = "Tokyo";
   %cities[6] = "NewYork";
   %cities[7] = "Hollywood";
      
   if($WorldMapZoomedIn !$= false)
   {
      // Select city to go next
      switch$($WorldMapZoomedIn)
      {
         case "Paris"    : %city = 0;
		   case "Fiji"     : %city = 1;
         case "London"   : %city = 2;
         case "HongKong" : %city = 3;
         case "Mexico"   : %city = 4;
         case "Tokyo"    : %city = 5;
         case "NewYork"  : %city = 6;
         case "Hollywood": %city = 7;
      }
      
      // Change viewpoint to next city
      %this.selectScene(%cities[(%city+1) % $CurPlayerUScene], 0);      
   }
   else
      %this.selectScene(Paris, 0);
}

function WorldMapGui::onTimer(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);

   if(!$OnResumeDlg && !$OnExitDlg)
   {
      if(WorldMapGui.animatingFeedback $= true)
      {
         %this.insideStudio = false;
         WMStudioButton.setBitmap("scriptsAndAssets/data/ui/menu/map/studio_n");      
      }
      else
      {
         // Check studio button
         %curMousePos = canvas.getCursorPos();
         %curMouseX = getWord(%curMousePos, 0);
         %curMouseY = getWord(%curMousePos, 1);
         %rect2 = GuiCenter.getPosition();
         if((%curMouseX > (552*%winScaleX)+getWord(%rect2,0) &&
             %curMouseY > (509*%winScaleY)+getWord(%rect2,1)))
         {
            if(%this.insideStudio $= false)
            {
               // Enter studio button
               sfxPlay(SFX_OVER);
            }
            %this.insideStudio = true;      
            WMStudioButton.setBitmap("scriptsAndAssets/data/ui/menu/map/studio_h");
         }
         else
         {
            if(%this.insideStudio $= true)
            {
               // Leave studio button
            }
            %this.insideStudio = false;
            WMStudioButton.setBitmap("scriptsAndAssets/data/ui/menu/map/studio_n");
         }
      }   
   }
   
   %this.timerID = scheduleObjLCA(%this, "HO", 30, "onTimer", 0);
}

// Called when globe is rotated by keyboard
function WorldMapGui::onRotateByKeyb(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
      
   if(%this.mouseDragging $= false && %this.zoomOutAfterTab $= false && $WorldMapZoomedIn $= false)
   {
	  %startPos = Canvas.getExtent();
      %startPosX = getWord(%startPos,0)/2;
      %startPosY = getWord(%startPos,1)/2;
      ArcBall.onMouseDown(%startPosX, %startPosY);
      
      %newPosX = %startPosX - ($mvLeftAction   *4)*%winScaleX + ($mvRightAction   *4)*%winScaleX;
      %newPosY = %startPosY - ($mvForwardAction*2)*%winScaleY + ($mvBackwardAction*2)*%winScaleY;
	  %sameAsPrev = (%startPosX $= %newPosX) && (%startPosY $= %newPosY);

	  if (!%sameAsPrev)
      {
		if (!%this.soundPlayingForKeyb)
		{
			%this.turnDelayKeyb = 0;
			sfxStop(%this.rotateSound );
	       %this.rotateSound = sfxPlay(SFX_ROLL);
	       %this.soundPlayingForKeyb = true;
		   }
	   }
	   else
	   {
	   //Alows a bit of dealy before turning the sound off, makes it sound slightly nicer.
			if (%this.turnDelayKeyb ++  $= 10)
			{
			   %this.soundPlayingForKeyb = false;
			   if (!%this.soundPlayingForMouse)
					sfxStop(%this.rotateSound);
			}
	   }
   
//      %newPosY = %startPosY;
      ArcBall.onMouseMove(%newPosX, %newPosY, Camera1);
      ArcBall.onMouseUp();
   }
   else
   {
	   %this.soundPlayingForKeyb = false;
	   if (!%this.soundPlayingForMouse)
			sfxStop(%this.rotateSound);
   }
   
   %this.rotateByKeybID = scheduleObjLCA(%this, "HO", 30, "onRotateByKeyb", 0);
}

function WorldMapGui::addDummies(%this)
{
   if(!isObject(Fiji_click_dummy))
   {
      new TSStatic(Fiji_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "15.2887 -5.15853 5.9";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(Fiji_click_dummy);
   }
     
   if(!isObject(Tokyo_click_dummy))
   {
      new TSStatic(Tokyo_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "8.41871 -10.2985 20.33";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(Tokyo_click_dummy);
   }
   
   if(!isObject(HongKong_click_dummy))
   {   
      new TSStatic(HongKong_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "2.40871 -15.0385 17.41";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(HongKong_click_dummy);
   }
   
   if(!isObject(Paris_click_dummy))
   {      
      new TSStatic(Paris_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "-10.5213 -0.548525 21.36";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(Paris_click_dummy);
   }
   
   if(!isObject(London_click_dummy))
   {      
      new TSStatic(London_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "-6.29129 4.10147 22.37";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(London_click_dummy);
   }
   
   if(!isObject(NewYork_click_dummy))
   {      
      new TSStatic(NewYork_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "1.08871 12.4215 19.76";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(NewYork_click_dummy);
   }
   
   if(!isObject(Mexico_click_dummy))
   {         
      new TSStatic(Mexico_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "3.93871 14.5215 13.93";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(Mexico_click_dummy);
   }
   
   if(!isObject(Hollywood_click_dummy))
   {         
      new TSStatic(Hollywood_click_dummy) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         Position = "10.4887 7.37148 19.96";
         rotation = "1 0 0 0";
         scale = "0.025 0.025 0.025";
         shapeName = "scriptsAndAssets/data/shapes/WorldMap/locations/click_dummy.dts";
         receiveSunLight = "1";
         receiveLMLighting = "1";
         useCustomAmbientLighting = "0";
         customAmbientLighting = "0 0 0 1";
         boxScale = "1 1 1";
         usePolysoup = "1";
         allowPlayerStep = "1";
            clickable = "1";
      };
      MissionGroup.add(Hollywood_click_dummy);
   }
}

// Called when the user clicks on the menu button
function WorldMapGui::goToMainMenu(%this)
{
   if(%this.exitingToMainMenu $= true)
      return;
      
   %this.exitingToMainMenu = true;
   
   MainMenuGui.playButtonPressSound();
   $ReplayButtonPressed = true;
      
   scheduleObjLCA(MainMenuGui, "HO", 300, "goHome", 0);   
}

// Called when the unlock city animation is done
function WorldMapGui::finishUnlockCity(%this, %obj)
{      
   // Show new city
   %city = %obj.getName();
   %this.SetHidden((%city @ "_grayedout"), true);
   %this.SetHidden(%city, false);
   
   // Sparks FTW!!
   for(%i = $LastUnlockedScene+1; %i <= $CurUnlockedScene; %i++)
   {
      %pos = getBoxCenter(%obj.getWorldBox());
      
      %scheduleTime = 0;
      for(%j=0; %j<30; %j++)
      {
         %pos2 = getWord(%pos,0)+getRandom(-100,100)/60 SPC 
                 getWord(%pos,1)+getRandom(-100,100)/60 SPC
                 getWord(%pos,2)+getRandom(-100,100)/60;
         scheduleObjLCA(%this, "HO", %scheduleTime, "StarPopEffect", 1, %pos2);
         %scheduleTime += 75;
      }
   }
   
   // Go back to normal
   $SceneJustUnlocked = false;   
   %this.tabHit = false;         
   %this.unlockCity = false;
   
   WMBackButton.setVisible(true);
   %this.animatingFeedback = false;              
      
   %this.updateClapperboards(false);
         
   if($WorldMapZoomedIn $= "Paris" && $CurFirstPlay $= 0)
      %this.SetHidden(Tutorial_clapperboard, false);
   
   // Hide back to main menu button
   WMBackMainMenuButton.setVisible(false);

   %this.zoomInID = -1;
   %this.tabHit = false;   
}

// Evaluate awards won (to be shown at HO screen)
function WorldMapGui::evaluateAwards(%this)
{
   %time = 0;
   %numAwards = 0;
   
   switch$($CurPlayerNum)
   {

   case 1:   
   
      // [19] Find all the hidden hints     
      if(PlayerProfile.StarsMini1 >= 40 && PlayerProfile.Award_all_hint_objects_1 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[19];//"You have won an award!\nPuzzle Master";
         %this.awardNum[%numAwards] = 19;
         PlayerProfile.Award_all_hint_objects_1 = 1;
         %numAwards++;
      }   
   
      // [18] Earn five stars for a Take
      if($StarsWonInTake >= 5 && PlayerProfile.Award_5star_take_1 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[18];//"You have won an award!\nCritical Favourite";
         %this.awardNum[%numAwards] = 18;
         PlayerProfile.Award_5star_take_1 = 1;
         %numAwards++;
      }      
      
      // [8] Collect all stars for this movie (spy)
      if($CurSceneName $= "SpyLevel" &&
         getWord(PlayerProfile.PlayerSpyStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake1,3) >= 5 &&
         PlayerProfile.Award_paris_1 $= 0)
      {
         %this.awardNum[%numAwards] = 8;
         PlayerProfile.Award_paris_1 = 1;
         %numAwards++;      
      }
      
      // [7] Collect all stars for this movie (gangster)
      if($CurSceneName $= "GangsterLevel" &&
         getWord(PlayerProfile.PlayerGangsterStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake1,3) >= 5 &&
         PlayerProfile.Award_newyork_1 $= 0)
      {
         %this.awardNum[%numAwards] = 7;
         PlayerProfile.Award_newyork_1 = 1;
         %numAwards++;      
      }   
      
      // [6] Collect all stars for this movie (scifi)
      if($CurSceneName $= "SciFiLevel" &&
         getWord(PlayerProfile.PlayerSciFiStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake1,3) >= 5 &&
         PlayerProfile.Award_hollywood_1 $= 0)
      {
         %this.awardNum[%numAwards] = 6;
         PlayerProfile.Award_hollywood_1 = 1;
         %numAwards++;      
      }
      
      // [5] Collect all stars for this movie (kungfu)
      if($CurSceneName $= "KungFuLevel" &&
         getWord(PlayerProfile.PlayerKungFuStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake1,3) >= 5 &&
         PlayerProfile.Award_hongkong_1 $= 0)
      {
         %this.awardNum[%numAwards] = 5;
         PlayerProfile.Award_hongkong_1 = 1;
         %numAwards++;      
      }
      
      // [4] Collect all stars for this movie (western)
      if($CurSceneName $= "WesternLevel" &&
         getWord(PlayerProfile.PlayerWesternStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake1,3) >= 5 &&
         PlayerProfile.Award_mexico_1 $= 0)
      {
         %this.awardNum[%numAwards] = 4;
         PlayerProfile.Award_mexico_1 = 1;
         %numAwards++;      
      }

      // [3] Collect all stars for this movie (monster)
      if($CurSceneName $= "MonsterLevel" &&
         getWord(PlayerProfile.PlayerMonsterStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake1,3) >= 5 &&
         PlayerProfile.Award_tokyo_1 $= 0)
      {
         %this.awardNum[%numAwards] = 3;
         PlayerProfile.Award_tokyo_1 = 1;
         %numAwards++;      
      }

      // [2] Collect all stars for this movie (monster)
      if($CurSceneName $= "MusicalLevel" &&
         getWord(PlayerProfile.PlayerMusicalStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake1,3) >= 5 &&
         PlayerProfile.Award_london_1 $= 0)
      {
         %this.awardNum[%numAwards] = 2;
         PlayerProfile.Award_london_1 = 1;
         %numAwards++;      
      }
      
      // [1] Collect all stars for this movie (dinosaur)
      if($CurSceneName $= "DinosaurLevel" &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake1,0) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake1,1) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake1,2) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake1,3) >= 5 &&
         PlayerProfile.Award_fiji_1 $= 0)
      {
         %this.awardNum[%numAwards] = 1;
         PlayerProfile.Award_fiji_1 = 1;
         %numAwards++;      
      }      
      
      // [11] Complete all takes of a movie
      if(PlayerProfile.Award_takes_movie_1 $= 0)
      {
         if(($CurSceneName $= "SpyLevel" &&
             getWord(PlayerProfile.PlayerSpyStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake1,3) >= 1) ||
            ($CurSceneName $= "GangsterLevel" &&
             getWord(PlayerProfile.PlayerGangsterStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake1,3) >= 1) ||
            ($CurSceneName $= "SciFiLevel" &&
             getWord(PlayerProfile.PlayerSciFiStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake1,3) >= 1) ||
            ($CurSceneName $= "KungFuLevel" &&
             getWord(PlayerProfile.PlayerKungFuStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake1,3) >= 1) ||
            ($CurSceneName $= "WesternLevel" &&
             getWord(PlayerProfile.PlayerWesternStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake1,3) >= 1) ||
            ($CurSceneName $= "MonsterLevel" &&
             getWord(PlayerProfile.PlayerMonsterStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake1,3) >= 1) ||
            ($CurSceneName $= "MusicalLevel" &&
             getWord(PlayerProfile.PlayerMusicalStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake1,3) >= 1) ||
            ($CurSceneName $= "DinosaurLevel" &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake1,0) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake1,1) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake1,2) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake1,3) >= 1))
         {            
            %this.awardText[%numAwards] = %this.awardWon[11];//"You have won an award!\nFull Production";
            %this.awardNum[%numAwards] = 11;
            PlayerProfile.Award_takes_movie_1 = 1;
            %numAwards++;
         }
      }
      
      // [21] Complete all takes of all movies
      if(PlayerProfile.Award_takes_game_1 $= 0)
      {         
         if(getWord(PlayerProfile.PlayerSpyStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake1,3) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake1,0) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake1,1) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake1,2) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake1,3) >= 1)
         {
            %this.awardNum[%numAwards] = 21;
            PlayerProfile.Award_takes_game_1 = 1;
            %numAwards++;
         }
      }

      // [20] Collect 150 Stars
      if($CurPlayerStars >= 150 && PlayerProfile.Award_150_stars_1 $= 0) 
      {
         %this.awardText[%numAwards] = %this.awardWon[20];//"You have won an award!\nHall of Fame";
         %this.awardNum[%numAwards] = 20;
         PlayerProfile.Award_150_stars_1 = 1;
         %numAwards++;
      }
   
   case 2:
   
      // [19] Find all the hidden hints
      if(PlayerProfile.StarsMini2 >= 40 && PlayerProfile.Award_all_hint_objects_2 $= 0)      
      {
         %this.awardText[%numAwards] = %this.awardWon[19];//"You have won an award!\nClue Master";
         %this.awardNum[%numAwards] = 2;
         PlayerProfile.Award_all_hint_objects_2 = 1;
         %numAwards++;
      }   
   
      // [18] Earn five stars for a Take
      if($StarsWonInTake >= 5 && PlayerProfile.Award_5star_take_2 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[18];//"You have won an award!\nCritical Favourite";
         %this.awardNum[%numAwards] = 18;
         PlayerProfile.Award_5star_take_2 = 1;
         %numAwards++;
      }
      
      // [8] Collect all stars for this movie (spy)
      if($CurSceneName $= "SpyLevel" &&
         getWord(PlayerProfile.PlayerSpyStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake2,3) >= 5 &&
         PlayerProfile.Award_paris_2 $= 0)
      {
         %this.awardNum[%numAwards] = 8;
         PlayerProfile.Award_paris_2 = 1;
         %numAwards++;      
      }
      
      // [7] Collect all stars for this movie (gangster)
      if($CurSceneName $= "GangsterLevel" &&
         getWord(PlayerProfile.PlayerGangsterStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake2,3) >= 5 &&
         PlayerProfile.Award_newyork_2 $= 0)
      {
         %this.awardNum[%numAwards] = 7;
         PlayerProfile.Award_newyork_2 = 1;
         %numAwards++;      
      }   
      
      // [6] Collect all stars for this movie (scifi)
      if($CurSceneName $= "SciFiLevel" &&
         getWord(PlayerProfile.PlayerSciFiStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake2,3) >= 5 &&
         PlayerProfile.Award_hollywood_2 $= 0)
      {
         %this.awardNum[%numAwards] = 6;
         PlayerProfile.Award_hollywood_2 = 1;
         %numAwards++;      
      }
      
      // [5] Collect all stars for this movie (kungfu)
      if($CurSceneName $= "KungFuLevel" &&
         getWord(PlayerProfile.PlayerKungFuStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake2,3) >= 5 &&
         PlayerProfile.Award_hongkong_2 $= 0)
      {
         %this.awardNum[%numAwards] = 5;
         PlayerProfile.Award_hongkong_2 = 1;
         %numAwards++;      
      }
      
      // [4] Collect all stars for this movie (western)
      if($CurSceneName $= "WesternLevel" &&
         getWord(PlayerProfile.PlayerWesternStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake2,3) >= 5 &&
         PlayerProfile.Award_mexico_2 $= 0)
      {
         %this.awardNum[%numAwards] = 4;
         PlayerProfile.Award_mexico_2 = 1;
         %numAwards++;      
      }

      // [3] Collect all stars for this movie (monster)
      if($CurSceneName $= "MonsterLevel" &&
         getWord(PlayerProfile.PlayerMonsterStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake2,3) >= 5 &&
         PlayerProfile.Award_tokyo_2 $= 0)
      {
         %this.awardNum[%numAwards] = 3;
         PlayerProfile.Award_tokyo_2 = 1;
         %numAwards++;      
      }

      // [2] Collect all stars for this movie (monster)
      if($CurSceneName $= "MusicalLevel" &&
         getWord(PlayerProfile.PlayerMusicalStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake2,3) >= 5 &&
         PlayerProfile.Award_london_2 $= 0)
      {
         %this.awardNum[%numAwards] = 2;
         PlayerProfile.Award_london_2 = 1;
         %numAwards++;      
      }
      
      // [1] Collect all stars for this movie (dinosaur)
      if($CurSceneName $= "DinosaurLevel" &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake2,0) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake2,1) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake2,2) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake2,3) >= 5 &&
         PlayerProfile.Award_fiji_2 $= 0)
      {
         %this.awardNum[%numAwards] = 1;
         PlayerProfile.Award_fiji_2 = 1;
         %numAwards++;      
      }      
      
      // [11] Complete all takes of a movie
      if(PlayerProfile.Award_takes_movie_2 $= 0)
      {
         if(($CurSceneName $= "SpyLevel" &&
             getWord(PlayerProfile.PlayerSpyStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake2,3) >= 1) ||
            ($CurSceneName $= "GangsterLevel" &&
             getWord(PlayerProfile.PlayerGangsterStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake2,3) >= 1) ||
            ($CurSceneName $= "SciFiLevel" &&
             getWord(PlayerProfile.PlayerSciFiStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake2,3) >= 1) ||
            ($CurSceneName $= "KungFuLevel" &&
             getWord(PlayerProfile.PlayerKungFuStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake2,3) >= 1) ||
            ($CurSceneName $= "WesternLevel" &&
             getWord(PlayerProfile.PlayerWesternStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake2,3) >= 1) ||
            ($CurSceneName $= "MonsterLevel" &&
             getWord(PlayerProfile.PlayerMonsterStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake2,3) >= 1) ||
            ($CurSceneName $= "MusicalLevel" &&
             getWord(PlayerProfile.PlayerMusicalStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake2,3) >= 1) ||
            ($CurSceneName $= "DinosaurLevel" &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake2,0) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake2,1) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake2,2) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake2,3) >= 1))
         {
            %this.awardText[%numAwards] = %this.awardWon[11];//"You have won an award!\nFull Production";
            %this.awardNum[%numAwards] = 11;
            PlayerProfile.Award_takes_movie_2 = 1;
            %numAwards++;
         }
      }
      
      // [21] Complete all takes of all movies
      if(PlayerProfile.Award_takes_game_2 $= 0)
      {
         if(getWord(PlayerProfile.PlayerSpyStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake2,3) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake2,0) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake2,1) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake2,2) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake2,3) >= 1)
         {
            %this.awardNum[%numAwards] = 21;
            PlayerProfile.Award_takes_game_2 = 1;
            %numAwards++;
         }
      }
      
      // [20] Collect 150 Stars
      if($CurPlayerStars >= 150 && PlayerProfile.Award_150_stars_2 $= 0) 
      {
         %this.awardText[%numAwards] = %this.awardWon[20];//"You have won an award!\nHall of Fame";
         %this.awardNum[%numAwards] = 20;
         PlayerProfile.Award_150_stars_2 = 1;
         %numAwards++;
      }
   
   case 3:
   
      // [19] Find all the hidden hints
      //if(PlayerProfile.HintObjs_3 + $HintObjectsFound >= 80 && PlayerProfile.Award_all_hint_objects_3 $= 0)   
      if(PlayerProfile.StarsMini3 >= 40 && PlayerProfile.Award_all_hint_objects_3 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[19];//"You have won an award!\nClue Master";
         %this.awardNum[%numAwards] = 19;
         PlayerProfile.Award_all_hint_objects_3 = 1;
         %numAwards++;
      }   
   
      // [18] Earn five stars for a Take
      if($StarsWonInTake >= 5 && PlayerProfile.Award_5star_take_3 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[18];//"You have won an award!\nCritical Favourite";
         %this.awardNum[%numAwards] = 18;
         PlayerProfile.Award_5star_take_3 = 1;
         %numAwards++;
      }
      
      // [8] Collect all stars for this movie (spy)
      if($CurSceneName $= "SpyLevel" &&
         getWord(PlayerProfile.PlayerSpyStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake3,3) >= 5 &&
         PlayerProfile.Award_paris_3 $= 0)
      {
         %this.awardNum[%numAwards] = 8;
         PlayerProfile.Award_paris_3 = 1;
         %numAwards++;      
      }
      
      // [7] Collect all stars for this movie (gangster)
      if($CurSceneName $= "GangsterLevel" &&
         getWord(PlayerProfile.PlayerGangsterStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake3,3) >= 5 &&
         PlayerProfile.Award_newyork_3 $= 0)
      {
         %this.awardNum[%numAwards] = 7;
         PlayerProfile.Award_newyork_3 = 1;
         %numAwards++;      
      }   
      
      // [6] Collect all stars for this movie (scifi)
      if($CurSceneName $= "SciFiLevel" &&
         getWord(PlayerProfile.PlayerSciFiStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake3,3) >= 5 &&
         PlayerProfile.Award_hollywood_3 $= 0)
      {
         %this.awardNum[%numAwards] = 6;
         PlayerProfile.Award_hollywood_3 = 1;
         %numAwards++;      
      }
      
      // [5] Collect all stars for this movie (kungfu)
      if($CurSceneName $= "KungFuLevel" &&
         getWord(PlayerProfile.PlayerKungFuStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake3,3) >= 5 &&
         PlayerProfile.Award_hongkong_3 $= 0)
      {
         %this.awardNum[%numAwards] = 5;
         PlayerProfile.Award_hongkong_3 = 1;
         %numAwards++;      
      }
      
      // [4] Collect all stars for this movie (western)
      if($CurSceneName $= "WesternLevel" &&
         getWord(PlayerProfile.PlayerWesternStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake3,3) >= 5 &&
         PlayerProfile.Award_mexico_3 $= 0)
      {
         %this.awardNum[%numAwards] = 4;
         PlayerProfile.Award_mexico_3 = 1;
         %numAwards++;      
      }

      // [3] Collect all stars for this movie (monster)
      if($CurSceneName $= "MonsterLevel" &&
         getWord(PlayerProfile.PlayerMonsterStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake3,3) >= 5 &&
         PlayerProfile.Award_tokyo_3 $= 0)
      {
         %this.awardNum[%numAwards] = 3;
         PlayerProfile.Award_tokyo_3 = 1;
         %numAwards++;      
      }

      // [2] Collect all stars for this movie (monster)
      if($CurSceneName $= "MusicalLevel" &&
         getWord(PlayerProfile.PlayerMusicalStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake3,3) >= 5 &&
         PlayerProfile.Award_london_3 $= 0)
      {
         %this.awardNum[%numAwards] = 2;
         PlayerProfile.Award_london_3 = 1;
         %numAwards++;      
      }
      
      // [1] Collect all stars for this movie (dinosaur)
      if($CurSceneName $= "DinosaurLevel" &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake3,0) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake3,1) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake3,2) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake3,3) >= 5 &&
         PlayerProfile.Award_fiji_3 $= 0)
      {
         %this.awardNum[%numAwards] = 1;
         PlayerProfile.Award_fiji_3 = 1;
         %numAwards++;      
      }      
      
      // [11] Complete all takes of a movie
      if(PlayerProfile.Award_takes_movie_3 $= 0)
      {
         if(($CurSceneName $= "SpyLevel" &&
             getWord(PlayerProfile.PlayerSpyStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake3,3) >= 1) ||
            ($CurSceneName $= "GangsterLevel" &&
             getWord(PlayerProfile.PlayerGangsterStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake3,3) >= 1) ||
            ($CurSceneName $= "SciFiLevel" &&
             getWord(PlayerProfile.PlayerSciFiStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake3,3) >= 1) ||
            ($CurSceneName $= "KungFuLevel" &&
             getWord(PlayerProfile.PlayerKungFuStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake3,3) >= 1) ||
            ($CurSceneName $= "WesternLevel" &&
             getWord(PlayerProfile.PlayerWesternStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake3,3) >= 1) ||
            ($CurSceneName $= "MonsterLevel" &&
             getWord(PlayerProfile.PlayerMonsterStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake3,3) >= 1) ||
            ($CurSceneName $= "MusicalLevel" &&
             getWord(PlayerProfile.PlayerMusicalStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake3,3) >= 1) ||
            ($CurSceneName $= "DinosaurLevel" &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake3,0) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake3,1) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake3,2) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake3,3) >= 1))
         {
            %this.awardText[%numAwards] = %this.awardWon[11];//"You have won an award!\nFull Production";
            %this.awardNum[%numAwards] = 11;
            PlayerProfile.Award_takes_movie_3 = 1;
            %numAwards++;
         }
      }
      
      // [21] Complete all takes of all movies
      if(PlayerProfile.Award_takes_game_3 $= 0)
      {
         if(getWord(PlayerProfile.PlayerSpyStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake3,3) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake3,0) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake3,1) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake3,2) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake3,3) >= 1)
         {
            %this.awardNum[%numAwards] = 21;
            PlayerProfile.Award_takes_game_3 = 1;
            %numAwards++;
         }
      }
      
      // [20] Collect 150 Stars
      if($CurPlayerStars >= 150 && PlayerProfile.Award_150_stars_3 $= 0) 
      {
         %this.awardText[%numAwards] = %this.awardWon[20];//"You have won an award!\nHall of Fame";         
         %this.awardNum[%numAwards] = 20;
         PlayerProfile.Award_150_stars_3 = 1;
         %numAwards++;
      }
   
   case 4:
   
      // [19] Find all the hidden hints
      if(PlayerProfile.StarsMini4 >= 40 && PlayerProfile.Award_all_hint_objects_4 $= 0)      
      {
         %this.awardText[%numAwards] = %this.awardWon[19];//"You have won an award!\nClue Master";
         %this.awardNum[%numAwards] = 4;
         PlayerProfile.Award_all_hint_objects_4 = 1;
         %numAwards++;
      }   

      // [18] Earn five stars for a Take
      if($StarsWonInTake >= 5 && PlayerProfile.Award_5star_take_4 $= 0)
      {
         %this.awardText[%numAwards] = %this.awardWon[18];//"You have won an award!\nCritical Favourite";
         %this.awardNum[%numAwards] = 18;
         PlayerProfile.Award_5star_take_4 = 1;
         %numAwards++;
      }
      
      // [8] Collect all stars for this movie (spy)
      if($CurSceneName $= "SpyLevel" &&
         getWord(PlayerProfile.PlayerSpyStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerSpyStarsTake4,3) >= 5 &&
         PlayerProfile.Award_paris_4 $= 0)
      {
         %this.awardNum[%numAwards] = 8;
         PlayerProfile.Award_paris_4 = 1;
         %numAwards++;      
      }
      
      // [7] Collect all stars for this movie (gangster)
      if($CurSceneName $= "GangsterLevel" &&
         getWord(PlayerProfile.PlayerGangsterStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerGangsterStarsTake4,3) >= 5 &&
         PlayerProfile.Award_newyork_4 $= 0)
      {
         %this.awardNum[%numAwards] = 7;
         PlayerProfile.Award_newyork_4 = 1;
         %numAwards++;      
      }   
      
      // [6] Collect all stars for this movie (scifi)
      if($CurSceneName $= "SciFiLevel" &&
         getWord(PlayerProfile.PlayerSciFiStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerSciFiStarsTake4,3) >= 5 &&
         PlayerProfile.Award_hollywood_4 $= 0)
      {
         %this.awardNum[%numAwards] = 6;
         PlayerProfile.Award_hollywood_4 = 1;
         %numAwards++;      
      }
      
      // [5] Collect all stars for this movie (kungfu)
      if($CurSceneName $= "KungFuLevel" &&
         getWord(PlayerProfile.PlayerKungFuStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerKungFuStarsTake4,3) >= 5 &&
         PlayerProfile.Award_hongkong_4 $= 0)
      {
         %this.awardNum[%numAwards] = 5;
         PlayerProfile.Award_hongkong_4 = 1;
         %numAwards++;      
      }
      
      // [4] Collect all stars for this movie (western)
      if($CurSceneName $= "WesternLevel" &&
         getWord(PlayerProfile.PlayerWesternStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerWesternStarsTake4,3) >= 5 &&
         PlayerProfile.Award_mexico_4 $= 0)
      {
         %this.awardNum[%numAwards] = 4;
         PlayerProfile.Award_mexico_4 = 1;
         %numAwards++;      
      }

      // [3] Collect all stars for this movie (monster)
      if($CurSceneName $= "MonsterLevel" &&
         getWord(PlayerProfile.PlayerMonsterStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerMonsterStarsTake4,3) >= 5 &&
         PlayerProfile.Award_tokyo_4 $= 0)
      {
         %this.awardNum[%numAwards] = 3;
         PlayerProfile.Award_tokyo_4 = 1;
         %numAwards++;      
      }

      // [2] Collect all stars for this movie (monster)
      if($CurSceneName $= "MusicalLevel" &&
         getWord(PlayerProfile.PlayerMusicalStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerMusicalStarsTake4,3) >= 5 &&
         PlayerProfile.Award_london_4 $= 0)
      {
         %this.awardNum[%numAwards] = 2;
         PlayerProfile.Award_london_4 = 1;
         %numAwards++;      
      }
      
      // [1] Collect all stars for this movie (dinosaur)
      if($CurSceneName $= "DinosaurLevel" &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake4,0) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake4,1) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake4,2) >= 5 &&
         getWord(PlayerProfile.PlayerDinosaurStarsTake4,3) >= 5 &&
         PlayerProfile.Award_fiji_4 $= 0)
      {
         %this.awardNum[%numAwards] = 1;
         PlayerProfile.Award_fiji_4 = 1;
         %numAwards++;      
      }      
      
      // [11] Complete all takes of a movie
      if(PlayerProfile.Award_takes_movie_4 $= 0)
      {
         if(($CurSceneName $= "SpyLevel" &&
             getWord(PlayerProfile.PlayerSpyStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerSpyStarsTake4,3) >= 1) ||
            ($CurSceneName $= "GangsterLevel" &&
             getWord(PlayerProfile.PlayerGangsterStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerGangsterStarsTake4,3) >= 1) ||
            ($CurSceneName $= "SciFiLevel" &&
             getWord(PlayerProfile.PlayerSciFiStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerSciFiStarsTake4,3) >= 1) ||
            ($CurSceneName $= "KungFuLevel" &&
             getWord(PlayerProfile.PlayerKungFuStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerKungFuStarsTake4,3) >= 1) ||
            ($CurSceneName $= "WesternLevel" &&
             getWord(PlayerProfile.PlayerWesternStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerWesternStarsTake4,3) >= 1) ||
            ($CurSceneName $= "MonsterLevel" &&
             getWord(PlayerProfile.PlayerMonsterStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerMonsterStarsTake4,3) >= 1) ||
            ($CurSceneName $= "MusicalLevel" &&
             getWord(PlayerProfile.PlayerMusicalStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerMusicalStarsTake4,3) >= 1) ||
            ($CurSceneName $= "DinosaurLevel" &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake4,0) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake4,1) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake4,2) >= 1 &&
             getWord(PlayerProfile.PlayerDinosaurStarsTake4,3) >= 1))
         {
            %this.awardText[%numAwards] = %this.awardWon[11];//"You have won an award!\nFull Production";
            %this.awardNum[%numAwards] = 11;
            PlayerProfile.Award_takes_movie_4 = 1;
            %numAwards++;
         }
      }
      
      // [21] Complete all takes of all movies
      if(PlayerProfile.Award_takes_game_3 $= 0)
      {
         if(getWord(PlayerProfile.PlayerSpyStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerSpyStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerGangsterStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerSciFiStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerKungFuStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerWesternStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerMonsterStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerMusicalStarsTake4,3) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake4,0) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake4,1) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake4,2) >= 1 &&
            getWord(PlayerProfile.PlayerDinosaurStarsTake4,3) >= 1)
         {
            %this.awardNum[%numAwards] = 21;
            PlayerProfile.Award_takes_game_4 = 1;
            %numAwards++;
         }
      }
      
      // [20] Collect 150 Stars
      if($CurPlayerStars >= 150 && PlayerProfile.Award_150_stars_4 $= 0) 
      {
         %this.awardText[%numAwards] = %this.awardWon[20];//"You have won an award!\nHall of Fame";         
         %this.awardNum[%numAwards] = 20;
         PlayerProfile.Award_150_stars_4 = 1;
         %numAwards++;
      }

   }
   
   if(%numAwards > 0)
      SavePlayerProfile();
      
      %time += 2000;
   
   for(%i=0; %i < %numAwards; %i++)
   {
      %text = %this.awardText[%i];
      %awardNum = %this.awardNum[%i];
      if(%text $= "")
         %text =  "      " @ %this.awardGeneric/*"You have won an award!"*/ @  "      ";
      
      scheduleObjLCA(WorldMapGui, "HO", %time, "showUnlockedAward", 2, %text, %awardNum);      
      
      %time += 3000;
   }
   
   return %time;
}

function WorldMapGui::showCursor(%this)
{
   //if(%this.hideCounter > 0)
      //%this.hideCounter = 0;
   //
   //if(%this.hideCounter $= 0)

   Canvas.showCursor();   
}

function WorldMapGui::hideCursor(%this)
{
   //if ($mouseLeftWindow)
   //{      
      //With the last engine changes we can call hide cursor several times
      if($RunMentor !$= 0)         
         Canvas.hideCursor();
      $mouseLeftWindow = false;
   //}
   //if(%this.hideCounter $= 0)
      //Canvas.hideCursor();
      //
   //%this.hideCounter = 1;
}

// Parse XML file looking for award tags
function WorldMapGui::loadAwardXML(%this)
{
   %path = "./scriptsAndAssets/data/ui/award.xml";
   
   %pXml = new SimXMLDocument();
   // Load and parse XML file.
   if(!%pXml.loadFile(%path))
   {
      echo("Failed to load " @ %path);
      return;
   }
   
   // Push the first child element named "award" onto 
   // the XML document stack.
   if(!%pXml.pushFirstChildElement("award"))
   {
      echo("Failed to load award tag.");
      return;
   }
   
   // Get award win texts
   if(!%pXml.pushFirstChildElement("awardgeneric" @ %i))
   {
      echo("Failed to load awardgeneric tag.");
      return;
   }
   %this.awardGeneric = %pXml.attribute("text");
   %pXml.popElement();
   
   for(%i=9; %i<=22; %i++)
   {
      if(%i $= 21) continue; // Ignore the 21th
      
      if(!%pXml.pushFirstChildElement("awardwon" @ %i))
      {
         echo("Failed to load awardwon" @ %i @ " tag.");
         return;
      }
      %this.awardWon[%i] = %pXml.attribute("text");
      %pXml.popElement();
   }   
   
   // Get tutorial text 1
   if(!%pXml.pushFirstChildElement("worldmaptut1"))
   {
      echo("Failed to load worldmaptut1 tag.");
      return;
   }
   %this.tutText1 = %pXml.attribute("text");
   %pXml.popElement();
   
   // Get tutorial text 2
   if(!%pXml.pushFirstChildElement("worldmaptut2"))
   {
      echo("Failed to load worldmaptut2 tag.");
      return;
   }
   %this.tutText2 = %pXml.attribute("text");
   %pXml.popElement();
	
   %pXml.popElement();
   
   %pXml.delete();   
   
   echo("Debug: Award WorldMapGui XML loaded");
}

// Visual feedback for the recently unlocked scenes
function WorldMapGui::showUnlockedAward(%this, %text, %awardNum)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %obj  = AwardUnlockedSceneTextHO;
   %objs = AwardUnlockedSceneBoxHO;
   %obja = AwardUnlockedSceneHO;
   
   switch(%awardNum)
   {
      // [1] Award_fiji
      case 1:
         %ex = 100; %ey = 201;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/fiji.png");
      // [2] Award_london
      case 2:
         %ex = 68; %ey = 198;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/london.png");
      // [3] Award_tokyo
      case 3:
         %ex = 71; %ey = 199;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/tokyo.png");
      // [4] Award_mexico
      case 4:
         %ex = 74; %ey =  190;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/mexico.png");
      // [5] Award_hongkong
      case 5:
         %ex = 76; %ey = 202;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/hongkong.png");
      // [6] Award_hollywood
      case 6:
         %ex = 122; %ey = 147;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/hollywood.png");
      // [7] Award_newyork
      case 7:
         %ex = 68; %ey = 203;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/newyork.png");
      // [8] Award_paris
      case 8:
         %ex = 91; %ey = 189;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/paris.png");
      // [9] Award_no_hints
      case 9:
         %ex = 72; %ey = 112;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/no_hints.png");
      // [10] Award_no_wrong_items
      case 10:
         %ex = 65; %ey = 117;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/no_wrong_items.png");
      // [11] Award_takes_movie
      case 11:
         %ex = 72; %ey = 141;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/takes_movie.png");
      // [12] Award_wildlife
      case 12:
         %ex = 104; %ey = 130;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/wildlife.png");
      // [13] Award_toys
      case 13:
         %ex = 122; %ey = 148;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/toys.png");
      // [14] Award_insects
      case 14:
         %ex = 99; %ey = 151;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/insects.png");
      // [15] Award_3objects_3seconds
      case 15:
         %ex = 89; %ey = 128;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/3objects_3seconds.png");
      // [16] Award_2objects_3seconds
      case 16:
         %ex = 73; %ey = 123;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/2objects_3seconds.png");
      // [17] Award_all_items_2minutes
      case 17:
         %ex = 79; %ey = 148;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/all_items_2minutes.png");
      // [18] Award_5star_take
      case 18:
         %ex = 64; %ey = 103;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/5star_take.png");
      // [19] Award_all_hint_objects
      case 19:
         %ex = 67; %ey = 161;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/all_hint_objects.png");
      // [20] Award_150_stars
      case 20:
         %ex = 96; %ey = 149;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/160_stars.png");
      // [21] Award_takes_game
      case 21:
         %ex = 96; %ey = 165;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/takes_game.png");
      // [22] Award_600_objects
      case 22:
         %ex = 94; %ey = 173;
         %obja.setDML("scriptsAndAssets/data/ui/menu/map/awards/400_objects.png");
   }
   
   %ex *= 0.3;
   %ey *= 0.3;
   
   %origPX = 235 + 60;
   %origPY = 399 + 70;
   
   %obja.setExtent(%ex*%winScaleX, %ey*%winScaleY);
   %obja.setPosition((%origPX-%ex/2)*%winScaleX, (%origPY-%ey/2)*%winScaleY);   
   
   %obj.setAlpha(0);
   %objs.setAlpha(0);
   %obja.setAlpha(0);
   
   %obj.setText(%text);
   
   %obj.setVisible(true);
   %objs.setVisible(true);
   %obja.setVisible(true);
      
   %obj.animateAlpha(1, 0, 500, "0 0");
   %objs.animateAlpha(1, 0, 500, "0 0");
   %obja.animateAlpha(1, 0, 500, "0 0");   
   
   scheduleObjLCA(%this, "HO", 1800, "showUnlockedAward2", 0);
}

function WorldMapGui::showUnlockedAward2(%this)
{
   %obj  = AwardUnlockedSceneTextHO;
   %objs = AwardUnlockedSceneBoxHO;
   %obja = AwardUnlockedSceneHO;
   
   %obj.animateAlpha(0, 0, 500, "0 0");
   %objs.animateAlpha(0, 0, 500, "0 0");
   %obja.animateAlpha(0, 0, 500, "0 0");
   
   scheduleObjLCA(%this, "HO", 1000, "showUnlockedAward3", 0);
}

function WorldMapGui::showUnlockedAward3(%this)
{
   %obj  = AwardUnlockedSceneTextHO;
   %objs = AwardUnlockedSceneBoxHO;
   %obja = AwardUnlockedSceneHO;
   
   %obj.setVisible(false);
   %objs.setVisible(false);
   %obja.setVisible(false);
}
