from __future__ import generators
import plus
import Arenas
import random
import Hazards
import math

class Box(Arenas.SuperArena):
    "Awesome stunt mayhem! Features loops, jumps, bumps, and more! But beware...if you fall into the AI cage, you'll have to fight! A fast bot and using the Orbit Cam is recommended."
    name = "Stunt Arena"
    preview = "stuntarena/stuntarena.bmp"
    game_types = ['OBSTACLE COURSE']
    extent = (-30, 30, 30, -30)

    def __init__(self):
        Arenas.SuperArena.__init__(self, "Arenas/stuntarena/stuntarena.gmf")
        #plus.Arena.__init__(self, "")
        plus.setBackColor(0,0,0)
        
        degrad = 0.01745
        self.AddStaticCamera("Static Cam 1", (0, 8, 10), (30*degrad,math.pi), 84*degrad)
	self.AddStaticCamera("Static Cam 2", (0, 15, 12), (45*degrad,math.pi), 84*degrad)
	self.AddStaticCamera("Static Cam 3", (0, 20, 14), (60*degrad,math.pi), 84*degrad)
	self.AddStaticCamera("Static Cam 4", (0, 24, 16), (75*degrad,math.pi), 84*degrad)
	self.AddWatchCamera("Watch Cam C", (0, 60, 0), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam N", (0, 60, 64), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam NE", (64, 60, 64), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam E", (64, 60, 0), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam SE", (64, 60, -64), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam S", (0, 60, -64), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam SW", (-64, 60, -64), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam W", (-64, 60, 0), (70, 110, 25*degrad, 10*degrad))
	self.AddWatchCamera("Watch Cam NW", (-64, 60, 64), (70, 110, 25*degrad, 10*degrad))
        self.AddStaticCamera("Photo Cam", (-8, 1, 64), (350*degrad,143*degrad), 70*degrad)

        self.players = ()
	self.robone = 0
	self.robtwo = 0
	self.robtre = 0
	self.robfor = 0
        
	self.robfiv = 0
	self.robsix = 0
	self.robsev = 0
	self.robeig = 0
        
	self.RegisterZone("0z", 1)
	self.RegisterZone("airblaster", 2)
        self.AddSound = plus.createSound("Sounds/droneloop.wav", False, (0, 0, 0))
        plus.loopSound(self.AddSound)

        
    def __del__(self):
        if self.endmusic:
            plus.stopSound(self.endmusic)
            plus.removeSound(self.endmusic)
        elif self.AddSound:
            plus.stopSound(self.AddSound)
            plus.removeSound(self.AddSound)
        Arenas.SuperArena.__del__(self)
        
    def AddShadowReceivers(self):
        self.SetShadowSource(5.897, 19.159, 5.899)
        
    def ZoneEvent(self, direction, id, robot, chassis):
        if id == 1:
            if robot==1:
	        if direction==1:
		    self.robone=1
	        elif direction==-1:
		    self.robone=0
		    
	    elif robot==2:
	        if direction==1:
		    self.robtwo=1
	        elif direction==-1:
		    self.robtwo=0

	    elif robot==3:
	        if direction==1:
		    self.robtre=1
	        elif direction==-1:
		    self.robtre=0

            elif robot==4:
	        if direction==1:
                    self.robfor=1
	        elif direction==-1:
		    self.robfor=0
        elif id == 2:
            if robot==1:
	        if direction==1:
		    self.robfiv=1
	        elif direction==-1:
		    self.robfiv=0
		    
	    elif robot==2:
	        if direction==1:
		    self.robsix=1
	        elif direction==-1:
		    self.robsix=0

	    elif robot==3:
	        if direction==1:
		    self.robsev=1
	        elif direction==-1:
		    self.robsev=0

            elif robot==4:
	        if direction==1:
                    self.robeig=1
	        elif direction==-1:
		    self.robeig=0


	return True

    def Activate(self, on):
        if on: self.players = plus.getPlayers()
        
        Arenas.SuperArena.Activate(self, on)
        
    def Tick(self):
	if self.robone==1:
	    plus.force(0, 0, 183 * plus.getWeight(0), 0)
	if self.robtwo==1:
	    plus.force(1, 0, 183 * plus.getWeight(1), 0)
	if self.robtre==1:
	    plus.force(2, 0, 183 * plus.getWeight(2), 0)
	if self.robfor==1:
	    plus.force(3, 0, 183 * plus.getWeight(3), 0)

	if self.robfiv==1:
	    plus.force(0, 0, 3000 * plus.getWeight(0), 0)
	if self.robsix==1:
	    plus.force(1, 0, 3000 * plus.getWeight(1), 0)
	if self.robsev==1:
	    plus.force(2, 0, 3000 * plus.getWeight(2), 0)
	if self.robeig==1:
	    plus.force(3, 0, 3000 * plus.getWeight(3), 0)

        return Arenas.SuperArena.Tick(self)
        
    def Winner(self, id1, id2):
        #Cut Music
        if self.AddSound:
                plus.stopSound(self.AddSound)
                plus.removeSound(self.AddSound)
                
        #print "Winners:", id1, id2
        return Arenas.SuperArena.Winner(self, id1, id2)
        
Arenas.register(Box)
