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

class DirtJockey(Missions.SuperMission):
    "Dig a hole for the foundation of a building going up in this urban lot."
    level_name = "Level 3"
    name = "Dirt Jockey"
    preview = "Levels/Level3/dirtjockey_preview.bmp"
    equipcost = 650
    pay = 1300
    perfectspeed = 1200 # seconds
    worstspeed = 1800
    
    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 = 3
    accuracy_type = 0
    
    def __init__(self, levelIndex):
        Missions.SuperMission.__init__(self, levelIndex)
        
        plus.setBackColor(0, 0, 0)
        
        self.missionID = 3
        self.instructions = "<text font fg_mcn12>A new building is going up in this urban lot. Engineers spray painted a nice neat perimeter line for you to dig a hole for the foundation. Use the excavator to dig the dirt out. Try to keep the bottom level, and don't go too deep. Waste drainage pipes are marked around the jobsite, so watch where you dig. Dump the dirt in the area marked off to the side. Try to be neat about it.</text>"
        
        self.excavator = plus.addVehicleWithRotation("Excavator", self.level.startpoint, self.level.startrotation)
        plus.enableVehicleControls(self.excavator, False)
        plus.setPinned(self.excavator, True)
        
        self.voiceovers['intro'] = "Sounds/Voiceovers/Missions/3/Description3-1.wav"
        self.voiceovers['pipes'] = "Sounds/Voiceovers/Missions/3/Description3-2.wav"
        self.voiceovers['area'] = "Sounds/Voiceovers/Missions/3/Description3-3.wav"
        
        self.objectives = ("Dig hole 1.5 meters deep in the marked area.","Radio in when you're done.",)
        self.missionEndsWithRadioIn = True
        self.holedug = 0
        self.bHoleFinished = False
        
        self.level.SetHelpArrowPosition(0, 67.0, 14.2, 55.0, 60.0) # Dig area

    def Introduction(self):
        # set initial camera & fade from black
        plus.animationCamera()
        plus.setCameraPosition(11.43, 27.3, 11.84)
        plus.setCameraRotation(.4, .8)
        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((11.43, 27.3, 11.84), (.4, .8), math.pi / 4, (45.5, 28, 53.8), (.645, 1.6), math.pi / 4, 0, 8, False) # white rectangle
        plus.animateCamera((45.5, 28, 53.8), (.645, 1.6), math.pi / 4, (45.5, 28, 53.8), (.765, -.15), math.pi / 4, 10, 14, False) # excavator
        yield 16.5
        
        plus.stopSound(self.curVoice)
        plus.removeSound(self.curVoice)
        self.curVoice = plus.createSound(self.voiceovers['pipes'])
        plus.playSound(self.curVoice)
        plus.animateCamera((45.5, 28, 53.8), (.765, -.15), math.pi / 4, (68.273, 24, 79), (.525, 1.18), math.pi / 4, 0, 2.5, False) #look at painted rect, pause
        plus.animateCamera((68.273, 24, 79), (.525, 1.18), math.pi / 4, (68.8, 22.8, 37.55), (.54, 1.54), math.pi / 4, 3, 6.5, False) #look at painted rect, pause
        yield 7
        
        plus.stopSound(self.curVoice)
        plus.removeSound(self.curVoice)
        self.curVoice = plus.createSound(self.voiceovers['area'])
        plus.playSound(self.curVoice)
        plus.animateCamera((68.8, 22.8, 37.55), (.54, 1.54), math.pi / 4, (67.26, 21.5, 52.558), (.375, .01), math.pi / 4, 0, 4, False) # zoom in on excavator, pause
        
        #play a generic (or specific) secondary comment
        
        yield 9
        
        # done
        yield 0
        
    def IntroComplete(self):
        Missions.SuperMission.IntroComplete(self)
        plus.enableVehicleControls(self.excavator, True)
        plus.setPinned(self.excavator, False)
        plus.resetClock()
        self.level.AddDepthGuage()

    def Tick(self):
        #"Do our stuff here -- called every tickInterval seconds."
        if self.holedug < 50:
            self.holedug = plus.getTerrainScore()  # [0-100] returned
        if self.holedug >= 50 and not self.bHoleFinished:
            plus.objectiveComplete(0, True)  # mission complete status is if we've dug 50% or better....accuracy improves the more you do, but it's not necessary
            self.bHoleFinished = True

        return Missions.SuperMission.Tick(self)

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

Missions.register(DirtJockey)
