def destroySelf(self):
     self.state = "dead"
     self.sides = 0
     self.resources = 0
     args = [3, self.pos.getPosition(), COLOR_CHARTREUSE, 150]
     #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
     network = PEG_mainLoop.mainLoop().entityDict['Network']
     network.mgr.send([PEG_effects.quickData(*args),])
 def revivePlayers(self):
     for e in self.enDict.values():
         if e.sides == 0:
             #TODO check distance from power source --> revive
             #do we give zero resources?
             if (e.pos.getPosition() - self.enDict['ThePSource'].pos.getPosition()).magnitude() < POWERSOURCE_ACTIVE_RADIUS:
                 e.sides = 3 
                 e.state = "alive"
                 print e.name, "revived"
                 #animation
                 args = [8, e.pos.getPosition(), e.color, ACTION_RADIUS]
                 self.send([(PEG_effects.quickData(*args)),])
 def serialRoutineOLD(self):
     serial = PEG_mainLoop.mainLoop().entityDict["SerialEntity"]
     action = serial.getActionString()
     if action == "starting sweep":
         print "sweep started"
         self.currentAction = action
         self.actionStart = pygame.time.get_ticks()
     elif action == "triggered sweep":
         print "sweep triggered"
         self.currentAction = ''
         network = PEG_mainLoop.mainLoop().entityDict['Network']
         data = dict()
         data['type'] = 'event'
         data['event'] = 'arduino'
         data['name'] = self.color
         data['arduino'] = action
         network.mgr.send([data,])
         args = [5, self.pos.getPosition(), self.color, ACTION_RADIUS]
         #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
         data = PEG_effects.quickData(*args)
         data['relay'] = 'True'
         network.mgr.send([data,])
         
         
     if self.currentAction == "starting sweep":
         timeSinceLastAction = pygame.time.get_ticks() - self.actionStart
         pygame.draw.circle(
                            PEG_mainLoop.mainLoop().screen,
                            COLOR_GRAY,
                            PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                            ACTION_RADIUS*timeSinceLastAction/ACTION_TIME + 1,
                            1
                            )
         pygame.draw.circle(
                            PEG_mainLoop.mainLoop().screen,
                            self.color,
                            PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                            ACTION_RADIUS,
                            1
                            )
 def processArduinoEvent(self,data):
     #try:
     print "got", data['arduino'], "from", data['name']
     #whirly bird for attacking
     if data['arduino'] == "sweep":
         for e in [item for item in self.enDict.values() if hasattr(item,"attackedBy")]:
             if self.enDict[data['name']].team != e.team:
                 if (self.enDict[data['name']].pos.getPosition() - e.pos.getPosition()).magnitude() < ACTION_RADIUS:
                     print self.enDict[data['name']].name, "attacks", e.name, "successfully"
                     e.attackedBy(self.enDict[data['name']])
                     #play effect
                     args = [7, e.pos.getPosition(), pedo_lookup.colorMap[data['name']], ACTION_RADIUS]
                     #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
                     self.send([PEG_effects.quickData(*args),])
                     
     #tomahawk for resources and construction
     if data['arduino'] == "tomahawk":
         
         flag1 = True
         for e in self.getBuildingEnList():
             if e.sides >= 5:
                 if (self.enDict[data['name']].pos.getPosition() - e.pos.getPosition()).magnitude() < POLYFACTORY_ACTIVE_RADIUS:
                     if self.enDict[data['name']].resources == self.enDict[data['name']].sides:
                         print self.enDict[data['name']].name, "has POLYFACTORIZED!!!!"
                         args = [9, self.enDict[data['name']].pos.getPosition(), self.enDict[data['name']].color, ACTION_RADIUS,self.enDict[data['name']].sides+1]
                         self.send([PEG_effects.quickData(*args),])
                         self.enDict[data['name']].sides += 1
                         self.enDict[data['name']].resources = 0
                         flag1 = False
                         break
         if flag1 and (self.enDict[data['name']].pos.getPosition() - self.enDict['ThePSource'].pos.getPosition()).magnitude() < POWERSOURCE_ACTIVE_RADIUS:
             print self.enDict[data['name']].name, "gathers 1 resource"
             self.enDict[data['name']].addResource()
             args = [5, self.enDict[data['name']].pos.getPosition(), self.enDict[data['name']].color, ACTION_RADIUS]
             sData = PEG_effects.quickData(*args)
             print  "in respones to arduino event, sending:", sData
             self.send([sData,])
         elif flag1 and self.enDict[data['name']].resources > 0:  #TODO change to 0, keep this way for testing
             self.enDict[data['name']].resources -= 1
             flag2 = True
             print self.enDict.values()
             for e in self.getBuildingEnList():
                 if (self.enDict[data['name']].pos.getPosition() - e.pos.getPosition()).magnitude() < BUILDING_RADIUS:
                     if self.enDict[data['name']].team == e.team:
                         print e.name, "upgraded by", data['name']
                         e.addSide()
                         flag2 = False
                         args = [9, e.pos.getPosition(), e.color, ACTION_RADIUS,e.sides+1]
                         self.send([PEG_effects.quickData(*args),])
                         break
             #no upgrade, then make new structure
             if flag2:
                 print self.enDict[data['name']], "created new building"
                 sdata = dict()
                 sdata['type'] = "position"
                 sdata['entity'] = "BuildingEn"
                 sdata['x'] = self.enDict[data['name']].pos.x
                 sdata['y'] = self.enDict[data['name']].pos.y
                 #TODO make some system for creating unique names
                 sdata['name'] = random.randint(0,5000) 
                 sdata['team'] = self.enDict[data['name']].team
                 sdata['sides'] = 1
                 self.processNetMessage(sdata)
                 #bad but w/e
                 self.enDict[sdata['name']].team = sdata['team']
                 args = [9, self.enDict[data['name']].pos.getPosition(), pedo_lookup.colorMap[sdata['team']], 3]
                 self.send([PEG_effects.quickData(*args),])
     #TODO hit explosion thing I dunno
     #play some effect for now?
     if data['arduino'] == "whirlybird":
         #TODO detect mode????
         #for now everything is visible
         pass