from __future__ import generators
import plus
import Missions
import Levels
import random
import math

class CatSkinner(Missions.SuperMission):
    "Clean up after Hurricane Elmo."
    level_name = "Level 2"
    name = "Cat Skinner"
    preview = "Levels/Level2/catskinner_preview.bmp"
    equipcost = 200
    pay = 735
    perfectspeed = 360 # seconds
    worstspeed = 960
    
    easy_speedfail = 20
    easy_safetyfail = 20
    easy_accuracyfail = 20
    easy_default = 50
    med_speedfail = 20
    med_safetyfail = 20
    med_accuracyfail = 20
    med_default = 50
    med_bonus = 70
    hard_speedfail = 20
    hard_safetyfail = 20
    hard_accuracyfail = 20
    hard_default = 50
    hard_bonus = 70
    
    missionNumber = 2
    accuracy_type = 3
    
    def __init__(self, levelIndex):
        Missions.SuperMission.__init__(self, levelIndex)
        
        plus.setBackColor(0, 0, 0)
        
        self.missionID = 2
        self.instructions = "<text font fg_mcn12>Hurricane Elmo left a trail of destruction last week. This cleanup job needs you to tear down the remains of a damaged garage and get all the debris together in one big pile next to the road. Use your bulldozer to knock down the structure and make a pass over the entire site to build the heap. Be careful around the swimming pool. The owners don't want debris in the bottom of it. And if you sink your dozer, you're finished. The house is salvageable, so stay away from it.</text>"
        
        self.bulldozer = plus.addVehicleWithRotation("Bulldozer", self.level.startpoint, self.level.startrotation)
        plus.setPinned(self.bulldozer, True)
        plus.enableVehicleControls(self.bulldozer, False)
        
        self.buildingDown = False
        
        self.voiceovers['intro'] = "Sounds/Voiceovers/Missions/2/Description2-1.wav"
        self.voiceovers['building'] = "Sounds/Voiceovers/Missions/2/Description2-2.wav"
        self.voiceovers['pool'] = "Sounds/Voiceovers/Missions/2/Description2-3.wav"
        
        self.objectives = ("Tear down garage.","Push pieces over to marked area.",)
        self.missionEndsWithRadioIn = True
        
        self.level.SetHelpArrowPosition(0, 53.0, 19.5, 46.5, 0.0) # Garage
        self.level.SetHelpArrowPosition(1, 36.0, 14.0, 64.0, 0.0) # Pile area

    def Introduction(self):
        # set initial camera & fade from black
        plus.animationCamera()
        plus.setCameraPosition(100, 19, 118)
        plus.setCameraRotation(0.20499, 3.7701)
        plus.setCameraFOV(math.pi / 4)
        plus.fadeFromBlack(.5, .5)

        #start playing music loop
        yield .75
        
        #load all sounds now to decrease lag later
        
        #intro cam, welcom comment
        self.curVoice = plus.createSound(self.voiceovers['intro'])
        plus.playSound(self.curVoice)
        plus.animateCamera((100, 19, 118), (0.20499, 3.7701), math.pi / 4, (30, 18, 120.5), (0.0249899, 3.315), math.pi / 4, 0, 5, False) # go down street
        plus.animateCamera((30, 18, 120.5), (0.0249899, 3.315), math.pi / 4, (21.55, 16.5, 67), (0.164989, 2.5799), math.pi / 4, 5, 10, False) # head toward bulldozer
        plus.animateCamera((21.55, 16.5, 67), (0.164989, 2.5799), math.pi / 4, (14, 16.9, 55.65), (0.259924, 1.19497), math.pi / 4, 10, 13, False) # zoom in on bulldozer, pause
        yield 14
        
        plus.stopSound(self.curVoice)
        plus.removeSound(self.curVoice)
        self.curVoice = plus.createSound(self.voiceovers['building'])
        plus.playSound(self.curVoice)
        plus.animateCamera((14, 16.9, 55.65), (0.259924, 1.19497), math.pi / 4, (34, 23.5, 58.3), (0.485008, 2.24002), math.pi / 4, 0, 5, False) # zoom in on garage, pause
        yield 8
        
        plus.stopSound(self.curVoice)
        plus.removeSound(self.curVoice)
        self.curVoice = plus.createSound(self.voiceovers['pool'])
        plus.playSound(self.curVoice)
        plus.animateCamera((34, 23.5, 58.3), (0.485008, 2.24002), math.pi / 4, (34, 23.5, 58.3), (0.365084, 1.13992), math.pi / 4, 0, 6, False) # zoom in on pool, pause
        plus.animateCamera((34, 23.5, 58.3), (0.365084, 1.13992), math.pi / 4, (48.47, 22.8, 64.6), (.215, 1.96), math.pi / 4, 8, 11, False) # look at house that user should not tear down
        
        #play a generic (or specific) secondary comment
        
        yield 12.5
        
        # done
        yield 0
        
    def IntroComplete(self):
        Missions.SuperMission.IntroComplete(self)
        plus.enableVehicleControls(self.bulldozer, True)
        plus.setPinned(self.bulldozer, False)
        plus.resetClock()
        
    def Tick(self):
        if not self.buildingDown and plus.isBuildingDown():
            plus.objectiveComplete(0, True)
            self.buildingDown = True
            self.level.KillHelpArrow(0)
        
        return Missions.SuperMission.Tick(self)

    def ZoneEvent(self, direction, id, objType):
        return True

Missions.register(CatSkinner)
