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

class LeverMonkey(Missions.SuperMission):
    "Knock down an old apartment building with the crane and wrecking ball."
    level_name = "Level 5"
    name = "Lever Monkey"
    preview = "Levels/Level5/lever_monkey_preview.bmp"
    equipcost = 320
    pay = 1200
    perfectspeed = 320 # 4:30 
    worstspeed = 1200 # 1 hour
    
    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 = 5
    accuracy_type = 4
    safety_type = 1
    
    def __init__(self, levelIndex):
        Missions.SuperMission.__init__(self, levelIndex)
        
        plus.setBackColor(0, 0, 0)
        
        self.missionID = 5
        self.instructions = "<text font fg_mcn12>We need to tear down an old apartment building. Use the crane and wrecking ball to knock down the structure. Don't leave any of it standing. There's another building next to the apartment, so be careful you don't damage it.</text>"
        
        self.crane = plus.addVehicleWithRotation("CraneWreckingBall", self.level.startpoint, self.level.startrotation)
        plus.enableVehicleControls(self.crane, False)
        
        self.buildingDown = False
        
        self.voiceovers['intro'] = "Sounds/Voiceovers/Missions/5/Description5-1.wav"
        self.voiceovers['building'] = "Sounds/Voiceovers/Missions/5/Description5-2.wav"
        
        self.objectives = ("Knock down building.",)
        
        self.level.SetHelpArrowPosition(0, 50.0, 23.0, 42.0, 0.0) # Apartment marker

    def Introduction(self):
        # set initial camera & fade from black
        plus.animationCamera()
        plus.setCameraPosition(101.44, 13.5, 23)
        plus.setCameraRotation(-.005, -1.315)
        plus.setCameraFOV(math.pi / 4)
        plus.fadeFromBlack(.5, .5)
	plus.park(self.crane, True)

        #start playing music loop
        yield .75
        
        #intro cam, welcom comment
        self.curVoice = plus.createSound(self.voiceovers['intro'])
        plus.playSound(self.curVoice)
        plus.animateCamera((101.44, 13.5, 23), (-.005, -1.315), math.pi / 4, (73.9, 16.4, 20.7), (-.02, -.96), math.pi / 4, 0, 5, False)
        plus.animateCamera((73.9, 16.4, 20.7), (-.02, -.96), math.pi / 4, (81.577, 19.957, 52.76), (.115, -1.92), math.pi / 4, 5, 9, False)
        yield 11
        
        plus.stopSound(self.curVoice)
        plus.removeSound(self.curVoice)
        self.curVoice = plus.createSound(self.voiceovers['building'])
        plus.playSound(self.curVoice)
        plus.animateCamera((81.577, 19.957, 52.76), (.115, -1.92), math.pi / 4, (81.577, 19.957, 52.76), (.085, -.86), math.pi / 4, 0, 4, False)
        yield 7
        
        # done
        yield 0
        
    def IntroComplete(self):
        Missions.SuperMission.IntroComplete(self)
        plus.enableVehicleControls(self.crane, True)
        plus.setPinned(self.crane, False)
        plus.resetClock()
	plus.park(self.crane, False)
        
    def Tick(self):
        if not self.buildingDown and plus.isBuildingDown():
            plus.objectiveComplete(0, True)
            self.buildingDown = True
            
        return Missions.SuperMission.Tick(self)

    def ZoneEvent(self, direction, id, objType):
        return True
        
Missions.register(LeverMonkey)
