示例#1
0
 def do_stuff(self):
     #send a message
     self.sendMsg("^3 Hello world. message")
     #send a chat
     self.sendMsg("^7 Hello world. chat", '')
     
     #creates a button
     self.send_button(1, 100, 100, 30, 15, "^7 Message", 255, pyinsim.ISB_DARK)
     
     #create a thread daemon that runs a process each [interval] seconds
     j=WorkDaemon(work_method=self.work_method, interval=1)
     j.start()
示例#2
0
    def do_stuff(self):
        #send a message
        self.sendMsg("^3 Hello world. message")
        #send a chat
        self.sendMsg("^7 Hello world. chat", '')

        #creates a button
        self.send_button(1, 100, 100, 30, 15, "^7 Message", 255,
                         pyinsim.ISB_DARK)

        #create a thread daemon that runs a process each [interval] seconds
        j = WorkDaemon(work_method=self.work_method, interval=1)
        j.start()
示例#3
0
    def change_focused_car(self):
        print("Changing focused car.")

        if (self.config.get("cam_changer", "reset_camera") == "yes"):
            print "Resetting camera to cam."
            self.cur_carcam = 0
            self.ccam_t.stop()
            self.ccam_t = WorkDaemon(work_method=self.change_carcam,
                                     interval=self.config.getfloat(
                                         "cam_changer", "camchange_interval"),
                                     run_once=False)
            self.ccam_t.start()

        self.sendMsg("/press tab", '')
示例#4
0
 def begin(self):
     print "Cam_Changer started."
     self.sendMsg("Cam_Changer started.")
     
     if(self.ccam_t is not None):
         self.ccam_t.stop()
     
     if(self.ccar_t is not None):
         self.ccar_t.stop()
     
     self.ccam_t=WorkDaemon(work_method=self.change_carcam,interval=self.config.getfloat("cam_changer", "camchange_interval"),run_once=False)
     self.ccar_t=WorkDaemon(work_method=self.change_focused_car,interval=self.config.getfloat("cam_changer", "carchange_interval"),run_once=False,run_first_time=False)
     self.cmsg_t=WorkDaemon(work_method=self.draw_big_button,interval=self.config.getfloat("cam_changer", "tickerchange_interval"),run_once=False)
     self.ccam_t.start()
     self.ccar_t.start()
     self.cmsg_t.start()
示例#5
0
 def car_contact (self, insim, info):
     InsimClient.car_contact(self, insim, info)
     print info
     mcar=info.A
     #track='KY1R'
     
     if(info.SpClose>1):
         driv_a=''
         driv_b=''
         try:
             driv_a=self.drivers[self.driversID[info.A.PLID]].playername
             driv_b=self.drivers[self.driversID[info.B.PLID]].playername
         except:
             print 'Cant locate driver name, maybe this key is deleted PLID A:',str(info.A.PLID),' B ',info.B.PLID
             return
         m= 'Contacto ^7A '+ driv_a+ ' y B'+ driv_b
         
         
         print m
         print info.Time
         self.sendMsg(m)
         
         p=[mcar.X/16, mcar.Y/16 ]
         
         #KY1R Nodes
         t_coords=[[-461,181],[-484,295],[-485 , 681],[-104 , 845],[187 , 594],[ 250 , 260],[54 , -81],[-354 , -57]]
         t_names=['T1','T1-T2','T2','T2-T3','T3','T3-T4','T4','T4-T1']
         #KY1 Nodes
         if(self.track=='KY1'):
             t_coords.reverse()
         
         
         tmp=0
         m=9000000
         t_f=0
         for pl in t_coords:
             p1=pl
             if(t_coords.index(pl)==len(t_coords)-1):
                 #last element
                 p2=t_coords[0]
             else:
                 p2=t_coords[t_coords.index(pl)+1]
             d=self.pointline_dist(p1, p2, p)
             print 'Distance To Line ',tmp, ' D: ',d
             if(d<m):
                 m=d
                 t_f=t_names[tmp]
                 
             tmp+=1
         #print 'Precaucion en ',t_f
         #self.sendMsg('^2Precaucion en '+str(t_f))
         if(self.config.get("crash_list","reg_crash")=="yes"):
             self.crash_msg_queue.appendleft(str(t_f))
             self.last_time_crash=time.time()
             self.add_crash(Crash_event(self.get_driver(info.A.PLID).get_playername(), self.get_driver(info.B.PLID).get_playername(),info.A.PLID,info.B.PLID, float(info.SpClose), p[0],p[1], t_f,info.Time))
             
             #schedule the message destroy
             WorkDaemon(self.pop_crash_queue,10,True).start()#destroy it in ten seconds 
示例#6
0
 def set_evt(self,tm,msg):
     '''
     tm time in seconds
     '''
     print "Set evt msg: ", msg, " time ",tm
     #stop thread
     if(self.timer_thread is not None):
         self.timer_thread.stop()
     
     self.msg=msg
     #create a new timer thread
     self.tm=tm
     self.timer_thread=WorkDaemon(self.draw_evt, 1, False)
     #start it
     self.first=True
     self.timer_thread.start()
     if(self.config.get("evt","send_rcm")=="yes"):
         self.sendRCM(msg)
示例#7
0
 def change_focused_car(self):
     print ("Changing focused car.")
     
     if(self.config.get("cam_changer","reset_camera")=="yes"):
         print "Resetting camera to cam."
         self.cur_carcam=0
         self.ccam_t.stop()
         self.ccam_t=WorkDaemon(work_method=self.change_carcam,interval=self.config.getfloat("cam_changer", "camchange_interval"),run_once=False)
         self.ccam_t.start()
     
     self.sendMsg("/press tab",'')
示例#8
0
    def begin(self):
        print "Cam_Changer started."
        self.sendMsg("Cam_Changer started.")

        if (self.ccam_t is not None):
            self.ccam_t.stop()

        if (self.ccar_t is not None):
            self.ccar_t.stop()

        self.ccam_t = WorkDaemon(work_method=self.change_carcam,
                                 interval=self.config.getfloat(
                                     "cam_changer", "camchange_interval"),
                                 run_once=False)
        self.ccar_t = WorkDaemon(work_method=self.change_focused_car,
                                 interval=self.config.getfloat(
                                     "cam_changer", "carchange_interval"),
                                 run_once=False,
                                 run_first_time=False)
        self.cmsg_t = WorkDaemon(work_method=self.draw_big_button,
                                 interval=self.config.getfloat(
                                     "cam_changer", "tickerchange_interval"),
                                 run_once=False)
        self.ccam_t.start()
        self.ccar_t.start()
        self.cmsg_t.start()
示例#9
0
class Cam_Sim(InsimClient):
    def __init__(self):
        InsimClient.__init__(self, "Cam_Changer")
        self.version = 0.2
        self.cur_carcam = 0
        #self.cams=[pyinsim.VIEW_CAM,pyinsim.VIEW_HELI,pyinsim.VIEW_DRIVER,pyinsim.VIEW_CUSTOM]
        self.cams = [
            str(x) for x in self.config.get("cam_changer", "cams").split(",")
        ]
        self.flags = pyinsim.ISF_LOCAL | pyinsim.ISF_MCI  #TODO we need MCI for position. FIX
        self.ccam_t = None
        self.ccar_t = None
        self.msg = "^7THis is example test."
        self.c_count = 1

    def draw_big_button(self):
        m = ""
        ic = self.config.get("cam_changer", "im")
        p = [
            int(x)
            for x in self.config.get("cam_changer", "props_tb").split(",")
        ]
        cpt = self.config.getint("cam_changer", "cpt")

        for i in range(self.c_count, min(self.c_count + cpt, 32 + 1)):
            if (self.pos_drivers[i] > 0):
                m += "^6" + str(i) + ". " + self.drivers[
                    self.pos_drivers[i]].playername.encode("latin-1") + " "

        if (m == ""):
            self.c_count = 1
            self.send_button(147,
                             p[1],
                             p[0],
                             p[2],
                             p[3],
                             msg=ic,
                             bs=pyinsim.ISB_DARK)
            return
        if (self.c_count == 31):
            m += " " * 4 + ic
        self.send_button(147,
                         p[1],
                         p[0],
                         p[2],
                         p[3],
                         msg=m,
                         bs=pyinsim.ISB_LEFT | pyinsim.ISB_DARK)

        self.c_count += cpt
        self.c_count = min(self.c_count, 32)
        if (self.c_count == 32):
            self.c_count = 1

    def change_carcam(self):
        scam = self.cams[self.cur_carcam]
        print "Changing car camera. ", scam

        if (self.iscustom(scam)):
            #custom cam
            self.set_custom_cam(scam)
            self.sendMsg("/view custom", '')

            self.sendMsg("/view reload", "")  #again, not sure

        else:
            #normal cam, set
            self.sendMsg("/view " + scam, '')

        if (not self.config.get("cam_changer", "random") == "yes"):
            if (self.cur_carcam < len(self.cams) - 1):
                self.cur_carcam += 1
            else:
                self.cur_carcam = 0
        else:
            #random
            self.cur_carcam = random.randint(0, len(self.cams) - 1)

    def iscustom(self, cam):
        if (cam == "cam" or cam == "fol" or cam == "heli" or cam == "driver"):
            return False
        return True

    def set_custom_cam(self, scam):
        #replace files
        orig = "./cams/" + scam + "/"
        dr = os.listdir(orig)
        dst = self.config.get("cam_changer", "lfs_path")
        print "Setting up Custom cam."

        try:
            for i in dr:
                shutil.copy("./cams/" + scam + "/" + i,
                            dst + "data/views/" + i)
            self.sendMsg("/view reload", "")

        except:
            print "Error copying custom camera files"

    def change_focused_car(self):
        print("Changing focused car.")

        if (self.config.get("cam_changer", "reset_camera") == "yes"):
            print "Resetting camera to cam."
            self.cur_carcam = 0
            self.ccam_t.stop()
            self.ccam_t = WorkDaemon(work_method=self.change_carcam,
                                     interval=self.config.getfloat(
                                         "cam_changer", "camchange_interval"),
                                     run_once=False)
            self.ccam_t.start()

        self.sendMsg("/press tab", '')

    def chat_message(self, insim, mso):
        InsimClient.chat_message(self, insim, mso)

        if (mso.Msg.count("start_cam_changer") > 0):
            self.begin()
        elif ("camtest" in mso.Msg):
            self.camtest()

    def camtest(self):
        self.sendMsg("CAMTEST")
        self.insim.send(pyinsim.ISP_CPP,
                        Pos=[-31373253, 30219388, 15 * 65536],
                        Flags=pyinsim.ISS_SHIFTU,
                        ViewPLID=41)

    def race_state(self, insim, rsp):
        InsimClient.race_state(self, insim, rsp)
        try:
            p = self.config.get("cam_changer", "props")
            p = [int(x) for x in p.split(",")]
            self.del_button(45, 0)
            if (self.current_driver_id > 0):
                drv = self.get_driver(self.current_driver_id)
                self.send_button(
                    45, p[1], p[0], p[2], p[3], "^7" + str(drv.position) +
                    ". " + (drv.playername.encode("latin-1")), 0,
                    pyinsim.ISB_DARK | pyinsim.ISB_LEFT)
        except:
            print "Error sending button"

    def race_start(self, insim, rsp):
        InsimClient.race_start(self, insim, rsp)
        self.c_count = 1

    def begin(self):
        print "Cam_Changer started."
        self.sendMsg("Cam_Changer started.")

        if (self.ccam_t is not None):
            self.ccam_t.stop()

        if (self.ccar_t is not None):
            self.ccar_t.stop()

        self.ccam_t = WorkDaemon(work_method=self.change_carcam,
                                 interval=self.config.getfloat(
                                     "cam_changer", "camchange_interval"),
                                 run_once=False)
        self.ccar_t = WorkDaemon(work_method=self.change_focused_car,
                                 interval=self.config.getfloat(
                                     "cam_changer", "carchange_interval"),
                                 run_once=False,
                                 run_first_time=False)
        self.cmsg_t = WorkDaemon(work_method=self.draw_big_button,
                                 interval=self.config.getfloat(
                                     "cam_changer", "tickerchange_interval"),
                                 run_once=False)
        self.ccam_t.start()
        self.ccar_t.start()
        self.cmsg_t.start()
示例#10
0
    def semaphore(self):
        color = ''
        msg = ''
        if (self.state == Custom_Launcher.CANCELLED_STATE):
            return
        print 'state ' + str(self.state)
        for i in range(0, self.num_lights):
            if (i < self.state):
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][1]
                color = '^' + self.config.get('custom_launcher', 'on_color')
            else:
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][0]
                color = '^' + self.config.get('custom_launcher', 'off_color')
            if (self.state == (self.num_lights + 1)):
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][1]
                #num_lights +1 in this state the lights, being on,  change it color and the race start indmediatly
                color = '^' + self.config.get('custom_launcher', 'start_color')
            #msg+=color+chr(149)+' '
            msg += color + l_style + ' '
        msg = msg[:-1]
        self.insim.send(pyinsim.ISP_BTN,
                        ReqI=1,
                        ClickID=100,
                        UCID=255,
                        BStyle=self.bstyle[self.config.getint(
                            'custom_launcher', 'bstyle')],
                        T=self.config.getint('custom_launcher', 'posy'),
                        L=self.config.getint('custom_launcher', 'posx'),
                        W=self.config.getint('custom_launcher', 'width'),
                        H=self.config.getint('custom_launcher', 'height'),
                        Text=msg)  #Button
        self.state += 1
        if (self.state == 1):
            #All lights are off. First wait
            self.print_log("Indicator deployed. All lights off.")
            t = self.gettime('wait_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state < (self.num_lights + 1)):
            #lights are being turned on
            self.print_log("Light " + str(self.state - 1) + " turned on.")
            t = self.gettime('light_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state == (self.num_lights + 1)):
            #all lights on. This is the last wait
            self.print_log("Light " + str(self.state - 1) +
                           " turned on. All lights on. Final delay started.")
            t = self.gettime('start_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state == (self.num_lights + 2)):
            #Already green flag, set new thread to delete the flag later
            print 'CAN START'
            t = time.time()
            est = pyinsim.time(
                int(self.launch_stime +
                    round(t - self.launch_tstamp, 4) * 1000))
            est = str(est[0]) + 'h' + str(est[1]) + 'm' + str(
                est[2]) + '.' + str(est[3]) + 's'
            m = self.config.get('custom_launcher', 'start_msg')

            if (not m == ''):
                self.sendMsg(m, ap='')

            self.print_log("RACE STARTED." + ' (EST: ' + est + ')')
            t = self.gettime('show_time')
            WorkDaemon(self.clear_semaphore, t[0], True).start()
示例#11
0
    def cancel_start(self):
        if (self.abort_counter > 0):
            return

        self.abort_counter = 1
        WorkDaemon(self.cancel_start_t, interval=0.35, run_once=True).start()
示例#12
0
class EVT(InsimClient):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        InsimClient.__init__(self, "Event_Timer")
        self.version=0.1
        self.flags=""
        self.timer_thread=None
        self.tm=0#time in seconds
        self.paused=True
        self.msg=""
        self.first=True
    def reset(self):
        pass
    
    def hidden_message(self, insim, msg):
        InsimClient.hidden_message(self, insim, msg)
        
        try:
            t=msg.Msg
            print t
            t=t.split(" ")
            print t
            cmd=t[0]
            
            if(cmd=="evtset"):
                #the last item is the time
                tm=float(t[-1:][0])*60
                m=" ".join(t[1:-1])
                print tm
                self.set_evt(tm, m)
            elif(cmd=="evtpause"):
                self.pause_evt()
            elif(cmd=="evtclear"):
                self.clear_evt()
            elif(cmd=="evtunpause"):
                self.unpause_evt()
                
        except:
            print "Command error"
            print msg.Msg
    def set_evt(self,tm,msg):
        '''
        tm time in seconds
        '''
        print "Set evt msg: ", msg, " time ",tm
        #stop thread
        if(self.timer_thread is not None):
            self.timer_thread.stop()
        
        self.msg=msg
        #create a new timer thread
        self.tm=tm
        self.timer_thread=WorkDaemon(self.draw_evt, 1, False)
        #start it
        self.first=True
        self.timer_thread.start()
        if(self.config.get("evt","send_rcm")=="yes"):
            self.sendRCM(msg)
            
    def clear_evt(self):
        if(self.timer_thread is not None):
            self.timer_thread.stop()
            
        self.del_button(125)
        self.del_button(126)
        self.first=True
        self.tm=0
        self.sendMsg("/rcc_all",'')
    def pause_evt(self):
        
        if(self.timer_thread is not None):
            self.timer_thread.pause()
    def unpause_evt(self):
        
        if(self.timer_thread is not None):
            self.timer_thread.unpause()
            
    def draw_evt(self):
        if(self.tm==-1):
            self.timer_thread.stop()
            return
        
        #2 buttons
        top=self.config.getint("evt","posy")
        left=self.config.getint("evt","posx")
        w=13
        h=9
        #format time
        u=(pyinsim.time(self.tm*1000))
        t_msg="%.2d"%(u[0]*60)+":"+"%.2d"%(u[2]) 
        cl="^3"
        if(self.tm<=59):
            cl='^1'
        t_msg=cl+t_msg
        self.send_button(125, top, left, w, h, t_msg, bs=pyinsim.ISB_DARK)
        
        if(self.first):
            w_m=60
            self.send_button(126, top, left+w, w_m, h, '^7'+self.msg, bs=pyinsim.ISB_LIGHT|pyinsim.ISB_LEFT)
        
        self.first=False
        self.tm-=1
示例#13
0
class Cam_Sim(InsimClient):
    
    def __init__(self):
        InsimClient.__init__(self, "Cam_Changer")
        self.version=0.2
        self.cur_carcam=0
        #self.cams=[pyinsim.VIEW_CAM,pyinsim.VIEW_HELI,pyinsim.VIEW_DRIVER,pyinsim.VIEW_CUSTOM]
        self.cams=[str(x) for x in self.config.get("cam_changer","cams").split(",")]
        self.flags=pyinsim.ISF_LOCAL|pyinsim.ISF_MCI #TODO we need MCI for position. FIX
        self.ccam_t=None
        self.ccar_t=None
        self.msg="^7THis is example test."
        self.c_count=1
    
    def draw_big_button(self):
        m=""
        ic=self.config.get("cam_changer","im")
        p=[int(x) for x in self.config.get("cam_changer","props_tb").split(",")]
        cpt=self.config.getint("cam_changer","cpt")
        
        for i in range(self.c_count,min(self.c_count+cpt,32+1)):
            if(self.pos_drivers[i]>0):
                m+="^6"+str(i)+". "+self.drivers[self.pos_drivers[i]].playername.encode("latin-1")+" "
       
        if(m==""):
            self.c_count=1
            self.send_button(147, p[1],p[0], p[2], p[3],msg=ic,bs=pyinsim.ISB_DARK)
            return
        if(self.c_count==31):
            m+=" "*4+ic    
        self.send_button(147, p[1],p[0], p[2], p[3],msg=m,bs=pyinsim.ISB_LEFT|pyinsim.ISB_DARK)
        
        self.c_count+=cpt
        self.c_count=min(self.c_count,32)
        if(self.c_count==32):
            self.c_count=1
            
    def change_carcam(self):
        scam=self.cams[self.cur_carcam]
        print "Changing car camera. ",scam

        if(self.iscustom(scam)):
            #custom cam
            self.set_custom_cam(scam)
            self.sendMsg("/view custom", '')
        
            self.sendMsg("/view reload", "")#again, not sure
            
        else:
            #normal cam, set
            self.sendMsg("/view "+scam, '')
        
        if(not self.config.get("cam_changer","random")=="yes"):
            if(self.cur_carcam<len(self.cams)-1):
                self.cur_carcam+=1
            else:
                self.cur_carcam=0
        else:
            #random
            self.cur_carcam=random.randint(0, len(self.cams)-1)
    
    def iscustom(self,cam):
        if(cam=="cam" or cam=="fol" or cam=="heli" or cam=="driver"):
            return False
        return True
    
    def set_custom_cam(self,scam):
        #replace files
        orig="./cams/"+scam+"/"
        dr=os.listdir(orig)
        dst=self.config.get("cam_changer","lfs_path")
        print "Setting up Custom cam."
        
        try:
            for i in dr:
                shutil.copy("./cams/"+scam+"/"+i, dst+"data/views/"+i)
            self.sendMsg("/view reload", "")
            
        except:
            print "Error copying custom camera files" 
         
    def change_focused_car(self):
        print ("Changing focused car.")
        
        if(self.config.get("cam_changer","reset_camera")=="yes"):
            print "Resetting camera to cam."
            self.cur_carcam=0
            self.ccam_t.stop()
            self.ccam_t=WorkDaemon(work_method=self.change_carcam,interval=self.config.getfloat("cam_changer", "camchange_interval"),run_once=False)
            self.ccam_t.start()
        
        self.sendMsg("/press tab",'')
        
       
    def chat_message(self,insim,mso):
        InsimClient.chat_message(self, insim, mso)
        
        if(mso.Msg.count("start_cam_changer")>0):
            self.begin()
        elif("camtest" in mso.Msg):
            self.camtest()
            
    def camtest(self):
        self.sendMsg("CAMTEST")
        self.insim.send(pyinsim.ISP_CPP,Pos=[-31373253,30219388,15*65536], Flags=pyinsim.ISS_SHIFTU,ViewPLID=41 )
    
    def race_state(self,insim, rsp):
        InsimClient.race_state(self, insim, rsp)
        try:
            p=self.config.get("cam_changer","props")
            p=[int(x) for x in p.split(",")]
            self.del_button(45, 0)
            if(self.current_driver_id>0):
                drv=self.get_driver(self.current_driver_id)
                self.send_button(45, p[1],p[0], p[2], p[3], "^7"+str(drv.position)+". "+(drv.playername.encode("latin-1")), 0, pyinsim.ISB_DARK|pyinsim.ISB_LEFT)
        except:
            print "Error sending button"
    def race_start(self,insim,rsp):
        InsimClient.race_start(self, insim, rsp)
        self.c_count=1
                
    def begin(self):
        print "Cam_Changer started."
        self.sendMsg("Cam_Changer started.")
        
        if(self.ccam_t is not None):
            self.ccam_t.stop()
        
        if(self.ccar_t is not None):
            self.ccar_t.stop()
        
        self.ccam_t=WorkDaemon(work_method=self.change_carcam,interval=self.config.getfloat("cam_changer", "camchange_interval"),run_once=False)
        self.ccar_t=WorkDaemon(work_method=self.change_focused_car,interval=self.config.getfloat("cam_changer", "carchange_interval"),run_once=False,run_first_time=False)
        self.cmsg_t=WorkDaemon(work_method=self.draw_big_button,interval=self.config.getfloat("cam_changer", "tickerchange_interval"),run_once=False)
        self.ccam_t.start()
        self.ccar_t.start()
        self.cmsg_t.start()
示例#14
0
 def begin(self):
     '''
     begin all stuff
     '''
     WorkDaemon(self.c_warn_led,1, False).start();#run everytime
     self.draw_list_button()