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 processNetMessage(self, data):
     if data['type'] == "position":
         self.parseEnData(data)          #has server specific routine inside
     if data['type'] == "time":
         self.gameTime = data['time'][1:len(data['time'])]   #time data is buffered with a character so we can start it with a 0
     if not self.server and data['type'] == "effect":        #client specific
         #should have position, id, etc 
         PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(
                                                                                            int(data['id']), 
                                                                                            Vector2d(int(data['x']),int(data['y'])),
                                                                                            (int(data['r']),int(data['g']),int(data['b'])), 
                                                                                            int(data['radius']),
                                                                                            int(data['sides'])
                                                                                            ))
     if not self.server and data['type'] == "state":        #client specific
         menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
         if data['state'] == "gameover":
             menu.gameover = True
             menu.winner = data['winner']
             menu.Ascore = data['Ateam']
             menu.Bscore = data['Bteam']
         elif data['state'] == "starting":
             menu.gameover = False
             
     if self.server and 'relay' in data:                     #server specific
             del data['relay']
             self.mgr.send(self.makeDefaultMessage(data))
             #print "relayed", data
     
     if self.server and data['type'] == "event":             #server specific
         if data['event'] == "arduino":
             if 'ThePSource' in self.enDict:
                 self.processArduinoEvent(data)
         
     #FIXK THIS
     if self.server and data['type'] == "init":              #server specific
         try: 
             m[1].name = data['name']
             print data['name'], " client is set"
         except: pass
         
         #now we check if all clients have been identified
         #this is kind of bad because we don't wait for extra clients to join, too bad
         #add maybe a 10 second grace period
         flag = True
         self.mgr.clntListlock.acquire()
         for e in self.mgr.clntList:
             if e.name == None:
                 flag = False
                 break
         self.mgr.clntListlock.release()
 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 processNetMessage(self, data):
        if data["type"] == "position":
            # We only update entities after one has been idnetififed
            if self.server or self.color:
                self.parseEnData(data)  # has server specific routine inside
        if data["type"] == "time":
            self.gameTime = data["time"]
        if not self.server and data["type"] == "effect":  # client specific
            # should have position, id, etc
            print "got effect from serva", data
            PEG_mainLoop.mainLoop().entityDict["EffectMenu"].addEffect(
                PEG_effects.quickEffect(
                    int(data["id"]),
                    Vector2d(int(data["x"]), int(data["y"])),
                    (int(data["r"]), int(data["g"]), int(data["b"])),
                    int(data["radius"]),
                    int(data["sides"]),
                )
            )
        if not self.server and data["type"] == "state":  # client specific
            menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
            if data["state"] == "gameover":
                menu.gameover = True
                menu.winner = data["winner"]
                menu.Ascore = data["Ateam"]
                menu.Bscore = data["Bteam"]
            elif data["state"] == "starting":
                menu.gameover = False

        if self.server and "relay" in data:  # server specific
            del data["relay"]
            self.send(self.makeDefaultMessage(data))
            # print "relayed", data

        if self.server and data["type"] == "event":  # server specific
            if data["event"] == "arduino":
                if "ThePSource" in self.enDict:
                    self.processArduinoEvent(data)
 def processNetMessage(self, data):
     if data['type'] == "position":
         #We only update entities after one has been idnetififed
         if self.server or self.color:
             self.parseEnData(data)          #has server specific routine inside
     if data['type'] == "time":
         self.gameTime = data['time']
     if not self.server and data['type'] == "effect":        #client specific
         #should have position, id, etc 
         print "got effect from serva", data
         PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(
                                                                                            int(data['id']), 
                                                                                            Vector2d(int(data['x']),int(data['y'])),
                                                                                            (int(data['r']),int(data['g']),int(data['b'])), 
                                                                                            int(data['radius']),
                                                                                            int(data['sides'])
                                                                                            ))
     if not self.server and data['type'] == "state":        #client specific
         menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
         if data['state'] == "gameover":
             menu.gameover = True
             menu.winner = data['winner']
             menu.Ascore = data['Ateam']
             menu.Bscore = data['Bteam']
         elif data['state'] == "starting":
             menu.gameover = False
             
     if self.server and 'relay' in data:                     #server specific
             del data['relay']
             self.send(self.makeDefaultMessage(data))
             #print "relayed", data
     
     if self.server and data['type'] == "event":             #server specific
         if data['event'] == "arduino":
             if 'ThePSource' in self.enDict:
                 self.processArduinoEvent(data)
 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