예제 #1
0
def updateSharedMemory():
    global sharedMem
    sharedmem = sharedMem.getsharedmem()
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()

    #now we'll build the slots, so we later know every single (possible) car
    carIds = range(0, ac.getCarsCount(), 1)
    for carId in carIds:
        #first we'll check wether there is a car for this id; as soon it returns -1
        #it's over
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(carId)
            sharedmem.vehicleInfo[carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(carId)
            sharedmem.vehicleInfo[carId].spLineLength=  ac.getCarState(carId, acsys.CS.NormalizedSplinePosition) 
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)
예제 #2
0
 def get_race_standings_position_in_class(self, identifier):
     if len(self.standings):
         #filter
         standings = []
         for s in self.standings:
             if s[2] == self.current_car_class.value and ac.isConnected(
                     s[0]) > 0:
                 standings.append((s[0], s[1]))
         p = [i for i, v in enumerate(standings) if v[0] == identifier]
         if len(p) > 0:
             if p[0] + 1 > len(standings):
                 return (len(standings), len(standings))
             return (p[0] + 1, len(standings))
     if self.session.value != 2:
         return (ac.getCarLeaderboardPosition(identifier), self.numCars)
     return (ac.getCarRealTimeLeaderboardPosition(identifier) + 1,
             self.numCars)
예제 #3
0
def updateSharedMemory():
    global sharedMem
    sharedmem = sharedMem.getsharedmem()
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()
    #now we'll build the slots, so we later know every single (possible) car
    carIds = range(0, ac.getCarsCount(), 1)
    for carId in carIds:
        #first we'll check wether there is a car for this id; as soon it returns -1
        #it's over
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(
                carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(
                carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(
                carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(
                carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(
                carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(
                carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(
                carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(
                carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[
                carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[
                carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[carId].spLineLength = ac.getCarState(
                carId, acsys.CS.NormalizedSplinePosition)
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)
            sharedmem.vehicleInfo[carId].finishStatus = ac.getCarState(
                carId, acsys.CS.RaceFinished)
 def updateTiming(self):
     """
     Рядовое обновление данных
     """
     for car in self.carList:
         if car is not None:
             postLogMessage('ac.isConnected(' + str(car.carId) + ') : ' +
                            str(ac.isConnected(car.carId)))
             car.connected = ac.isConnected(car.carId) == 1
             if not car.connected:  # отключённые машины не обновляем
                 continue
             # Если количество кругов, пройденных пилотом, в игре больше, чем в структуре car, обновляем данные по кругам
             newLapsCompleted = ac.getCarState(car.carId, acsys.CS.LapCount)
             if car.lapsCompleted < newLapsCompleted:
                 postLogMessage('car' + str(car.carId) +
                                ' per-lap timing update')
                 # Покруговые обновления
                 car.lapsCompleted = newLapsCompleted
                 car.lastLap = ac.getCarState(car.carId, acsys.CS.LastLap)
                 car.bestLap = ac.getCarState(car.carId, acsys.CS.BestLap)
                 car.totalTime += car.lastLap
                 car.lapPostTime = self.session_time
                 car.isFinished = ac.getCarState(car.carId,
                                                 acsys.CS.RaceFinished)
                 # postLogMessage('Per-lap update OK')
             # Постоянные обновления
             # postLogMessage('Per-iterval update')
             car.totalDistance = car.lapsCompleted + ac.getCarState(
                 car.carId, acsys.CS.NormalizedSplinePosition)
             car.isInPitlane = ac.isCarInPitlane(car.carId)
             car.isInPit = ac.isCarInPit(car.carId)
             car.leaderboardPosition = ac.getCarLeaderboardPosition(
                 car.carId)
             car.realTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                 car.carId)
             car.isFinished = ac.getCarState(car.carId,
                                             acsys.CS.RaceFinished)
def acUpdate(deltaT):
    # TIMERS
    global timer0, timer1, timer2

    # VARIABLES
    global totalDrivers
    global drivers
    global fastest_lap

    global race_started, replay_started, quali_started

    global qualify_session_time

    global replay_file
    global replay_data

    # Widgets
    global leaderboardWindow, driverWidget, driverComparisonWidget

    # LABELS
    global leaderboard
    global lapCountTimerLabel, leaderboardBaseLabel, leaderboardInfoBackgroundLabel, leaderboardBackgroundLabel
    global flagLabel

    # ============================
    # UPDATE TIMERS
    timer0 += deltaT
    timer1 += deltaT
    timer2 += deltaT
    # ============================

    # ================================================================
    #                            RACES
    # ================================================================
    if info.graphics.session == 2:

        # 10 times per second
        if timer2 > 0.1:
            timer2 = 0

            # =============================
            # SAVE SPLIT TIMES
            for d in drivers:
                if ac.isConnected(d.id) == 0: continue
                current_split = d.get_split_id(ac.getCarState(d.id, acsys.CS.NormalizedSplinePosition))
                if d.current_split != current_split: # save split time at each split of the track
                    d.split_times[current_split-1] = time.time()
                    d.current_split = current_split

        # 3 times per second
        if timer1 > 0.3:
            # CHECK RACE RESTART
            if race_started and info.graphics.completedLaps == 0 and info.graphics.iCurrentTime == 0:
                race_started = False

            # CHECK RACE START
            if not race_started and info.graphics.iCurrentTime > 0:
                # RESET THINGS
                fastest_lap = MAX_LAP_TIME
                LeaderboardRow.FASTEST_LAP_ID = -1
                for row in leaderboard: # clean the fastest lap marker
                    row.mark_fastest_lap()
                # in case we are coming from a qualify
                ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1)
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_RACE)
                ac.setVisible(lapCountTimerLabel, 1)

                race_started = True
                quali_started = False
                for d in drivers:
                    d.starting_position = ac.getCarLeaderboardPosition(d.id)
                    d.tyre = ac.getCarTyreCompound(d.id)
                    d.pits = 0
                replay_file = setup_replay_file(drivers, info.graphics.numberOfLaps) # save starting info on the drivers

            # ============================
            # POSITION UPDATE
            for i in range(totalDrivers):
                pos = ac.getCarRealTimeLeaderboardPosition(i)
                connected = ac.isConnected(i)
                if connected == 0: # mark unconnected drivers
                    leaderboard[pos].mark_out()
                    drivers[i].out = True
                else:
                    leaderboard[pos].mark_in()
                    drivers[i].out = False
                leaderboard[pos].update_name(i)

                # OVERTAKE
                if pos != drivers[i].position: # there was an overtake
                    drivers[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER # set timer
                    if pos < drivers[i].position:
                        leaderboard[pos].mark_green_position()
                    elif pos > drivers[i].position:
                        leaderboard[pos].mark_red_position()
                elif drivers[i].timer <= 0:
                    leaderboard[pos].mark_white_position()
                else:
                    drivers[i].timer -= timer1
                drivers[i].position = pos
                # END OVERTAKE

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            # ============================
            # FLAGS
            if info.graphics.flag == 1:
                ac.setBackgroundTexture(flagLabel, FC.BLUE_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 2:
                ac.setBackgroundTexture(flagLabel, FC.YELLOW_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 5:
                ac.setBackgroundTexture(flagLabel, FC.CHECKERED_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 0:
                ac.setVisible(flagLabel, 0)

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            # ============================
            # SERVER LAP
            for i in range(totalDrivers):
                drivers[i].current_lap = ac.getCarState(i, acsys.CS.LapCount)
            lc = max((drivers[i].current_lap for i in range(totalDrivers))) + 1
            if lc >= info.graphics.numberOfLaps:
                ac.setVisible(lapCountTimerLabel, 0)
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_FINAL_LAP)
            else:
                ac.setText(lapCountTimerLabel, "%d / %d" % (lc, info.graphics.numberOfLaps))

            # ===========================
            # CALCULATE TIME DIFERENCES
            dPosition = sorted(drivers, key=lambda x: x.position)
            if LeaderboardRow.update_type == INFO_TYPE.GAPS:
                for i in range(1, len(dPosition)):
                    driver_ahead, driver = dPosition[i-1], dPosition[i]
                    timeDiff = driver.split_times[driver.current_split - 1] - driver_ahead.split_times[driver.current_split - 1]
                    if timeDiff < 0: continue # ignore these times, happens on overtakes
                    if driver.position > totalDrivers: continue # might try to update before it is possible
                    driver.timeDiff = timeDiff
                    if timeDiff > 60:
                        leaderboard[driver.position].update_time("+1 MIN")
                    else:
                        leaderboard[driver.position].update_time("+" + time_to_string(timeDiff*1000))
                leaderboard[0].update_time("Interval") # Force it
            elif LeaderboardRow.update_type == INFO_TYPE.POSITIONS:
                for d in dPosition:
                    posDiff = d.starting_position - d.position - 1
                    leaderboard[d.position].update_positions(posDiff)

            # ============================
            # MARK FASTEST LAP
            if lc > FC.FASTEST_LAP_STARTING_LAP:
                for d in drivers:
                    lap = ac.getCarState(d.id, acsys.CS.BestLap)
                    if lap != 0 and lap < fastest_lap:
                        fastest_lap = lap
                        fastest_lap_banner.show(lap, ac.getDriverName(d.id))
                        LeaderboardRow.FASTEST_LAP_ID = d.id
                        if replay_file:
                            write_fastest_lap(replay_file, info.graphics.completedLaps, info.graphics.iCurrentTime, d, fastest_lap)
                for row in leaderboard:
                    row.mark_fastest_lap()

            # ============================
            # PITS MARKER
            for row in leaderboard:
                if ac.isCarInPitline(row.driverId) == 1:
                    row.mark_enter_pits()
                    drivers[row.driverId].tyre = ac.getCarTyreCompound(row.driverId) # maybe will change tyre
                else:
                    row.mark_left_pits()
                if time.time() - drivers[row.driverId].pit_time > 20 and ac.isCarInPit(row.driverId):
                    drivers[row.driverId].pits += 1
                    drivers[row.driverId].pit_time = time.time()

            # ============================
            # CHANGE CAR FOCUS AND DRIVER WIDGET
            if race_started:
                id = ac.getFocusedCar()
                if drivers[id].position <= totalDrivers: # in case it wasnt updated yet
                    driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
                    if drivers[id].position == 0:
                        driverComparisonWidget.hide()
                    else:
                        for d in drivers: # find driver ahead
                            if d.position == drivers[id].position - 1:
                                driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
                                break
            else:
                driverWidget.hide()
                driverComparisonWidget.hide()

            # ========================================================
            # SAVE DRIVER STATUS IN A FILE TO LOAD ON REPLAY
            if replay_file:
                write_driver_info(replay_file, info.graphics.completedLaps, info.graphics.iCurrentTime, drivers)
            # ========================================================


    # ================================================================
    #                        QUALIFY / PRACTICE
    # ================================================================
    elif info.graphics.session == 1 or (info.graphics.session == 0 and info.graphics.status != 1):

        # 3 times per second
        if timer1 > 0.3:
            # =============================================
            # QUALIFY RESTART
            if quali_started and qualify_session_time - info.graphics.sessionTimeLeft < 1:
                quali_started = False

            # =============================================
            # QUALIFY START
            if not quali_started:
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_QUALI)
                if (info.graphics.session == 0 and info.graphics.status != 0):
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_PRACTICE)
                ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1)
                qualify_session_time = info.graphics.sessionTimeLeft
                fastest_lap = MAX_LAP_TIME
                LeaderboardRow.FASTEST_LAP_ID = -1
                quali_started = True
                race_started = False

            # =============================================
            # SAVE BEST LAPS FOR EACH DRIVER
            for i in range(totalDrivers):
                lap = ac.getCarState(i, acsys.CS.BestLap)
                if lap != 0:
                    drivers[i].best_lap = lap
                if lap != 0 and lap < fastest_lap:
                    fastest_lap = lap
                    fastest_lap_banner.show(lap, ac.getDriverName(i))

                # MARK IN/OUT DRIVERS
                connected = ac.isConnected(i)
                if connected == 0: # mark unconnected drivers
                    drivers[i].out = True
                else:
                    drivers[i].out = False
                
            # =============================================
            # MANAGE LEADERBOARD

            # Sorting: sort drivers by this order 1. in or out drivers, 2. best lap, 3. driver id
            dPosition = sorted(drivers, key=lambda d: (d.out, d.best_lap, d.id))

            for i in range(totalDrivers):
                if dPosition[i].out:
                    leaderboard[i].mark_out()
                else:
                    leaderboard[i].mark_in()

                leaderboard[i].update_name(dPosition[i].id)
                if dPosition[i].best_lap == MAX_LAP_TIME:
                    leaderboard[i].update_time("NO TIME")
                elif i == 0:
                    leaderboard[i].update_time(time_to_string(dPosition[i].best_lap))
                else:
                    timeDiff = dPosition[i].best_lap - dPosition[0].best_lap
                    if timeDiff > 60000:
                        leaderboard[i].update_time("+1 MIN")
                    else:
                        leaderboard[i].update_time("+" + time_to_string(timeDiff))

                # OVERTAKES
                if i != dPosition[i].position: # there was an overtake on this driver
                    dPosition[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER
                    if i < dPosition[i].position:
                        leaderboard[i].mark_green_position()
                    elif i > dPosition[i].position:
                        leaderboard[i].mark_red_position()
                elif dPosition[i].timer <= 0:
                    leaderboard[i].mark_white_position()
                else:
                    dPosition[i].timer -= timer1
                dPosition[i].position = i
                # END OVERTAKE

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            if quali_started:
                if info.graphics.sessionTimeLeft < 0:
                    ac.setText(lapCountTimerLabel, "0:00")
                else:
                    timeText = time_to_string(info.graphics.sessionTimeLeft)[:-4]
                    ac.setText(lapCountTimerLabel, "0:00"[:-len(timeText)] + timeText)
                if info.graphics.sessionTimeLeft < qualify_session_time / 5:
                    ac.setFontColor(lapCountTimerLabel, 1,0,0,1)

            driverWidget.hide()
            driverComparisonWidget.hide()


    # ================================================================
    #                            REPLAYS
    # ================================================================
    elif info.graphics.status == 1:

        # three times per second
        if timer1 > 0.3:
            if not replay_started:
                if info.graphics.iCurrentTime > 0:
                    replay_data = load_replay_file(drivers)
                    replay_started = True

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            # ============================
            # GET DATA FOR THIS UPDATE
            if replay_data:
                new_positions = lookup_data(info.graphics.completedLaps, info.graphics.iCurrentTime, replay_data, drivers)

                # ============================
                # POSITION UPDATE
                for i in range(totalDrivers):
                    pos = new_positions[i]
                    if drivers[i].out: # mark unconnected drivers
                        leaderboard[pos].mark_out()
                    else:
                        leaderboard[pos].mark_in()
                    leaderboard[pos].update_name(i)

                    # OVERTAKE
                    if pos != drivers[i].position: # there was an overtake
                        drivers[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER # set timer
                        if pos < drivers[i].position:
                            leaderboard[pos].mark_green_position()
                        elif pos > drivers[i].position:
                            leaderboard[pos].mark_red_position()
                    elif drivers[i].timer <= 0:
                        leaderboard[pos].mark_white_position()
                    else:
                        drivers[i].timer -= timer1
                    drivers[i].position = pos
                    # END OVERTAKE

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            # ============================
            # GET FASTEST LAP UPDATE
            if replay_data:
                fl_data = lookup_fastest_lap(info.graphics.completedLaps, info.graphics.iCurrentTime, replay_data)
                if fl_data:
                    display_time = FC.FASTEST_LAP_DISPLAY_TIME - (info.graphics.iCurrentTime - fl_data[0]) / 1000
                    fastest_lap_banner.show(fl_data[2], ac.getDriverName(fl_data[1]), timer=display_time) # display only for the time left

            # ============================
            # SERVER LAP
            if replay_data:
                lc = max((drivers[i].current_lap for i in range(totalDrivers))) + 1
                if lc >= replay_data['nLaps']:
                    ac.setVisible(lapCountTimerLabel, 0)
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_FINAL_LAP)
                else:
                    ac.setText(lapCountTimerLabel, "%d / %d" % (lc, replay_data['nLaps']))
                    ac.setVisible(lapCountTimerLabel, 1)
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_RACE)

            # ============================
            # PITS MARKER
            for row in leaderboard:
                if ac.isCarInPitline(row.driverId) == 1:
                    row.mark_enter_pits()
                else:
                    row.mark_left_pits()

            # ============================
            # DRIVER WIDGET UPDATE
            if replay_started:
                id = ac.getFocusedCar()
                if drivers[id].position <= totalDrivers: # in case it wasnt updated yet
                    driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
                    if drivers[id].position == 0:
                        driverComparisonWidget.hide()
                    else:
                        for d in drivers: # find driver ahead
                            if d.position == drivers[id].position - 1:
                                driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
                                break
            else:
                driverWidget.hide()
                driverComparisonWidget.hide()

            # ============================
            # UPDATE TIMES
            if replay_data:
                for row in leaderboard:
                    if LeaderboardRow.update_type == INFO_TYPE.GAPS:
                        row.update_time("+" + time_to_string(drivers[row.driverId].timeDiff*1000))
                        if row.row == 0:
                            row.update_time("Interval") # Force it
                    elif LeaderboardRow.update_type == INFO_TYPE.POSITIONS:
                        posDiff = drivers[row.driverId].starting_position - drivers[row.driverId].position - 1
                        row.update_positions(posDiff)
예제 #6
0
def updateSharedMemory():
    global sharedMem
    global packetID

    sharedmem = sharedMem.getsharedmem()
    sharedmem.packetID = -1
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()

    carIds = range(0, ac.getCarsCount(), 1)

    for carId in carIds:
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(
                carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(
                carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(
                carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(
                carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(
                carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(
                carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(
                carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(
                carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[
                carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[
                carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[carId].splinePosition = ac.getCarState(
                carId, acsys.CS.NormalizedSplinePosition)
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)

            if libInit == 1 and carId == 0:
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    0] = funcGetSuspensionDamage(carId, 0)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    1] = funcGetSuspensionDamage(carId, 1)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    2] = funcGetSuspensionDamage(carId, 2)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    3] = funcGetSuspensionDamage(carId, 3)
                sharedmem.vehicleInfo[
                    carId].engineLifeLeft = funcGetEngineLifeLeft(carId)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    0] = funcGetTyreInflation(carId, 0)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    1] = funcGetTyreInflation(carId, 1)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    2] = funcGetTyreInflation(carId, 2)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    3] = funcGetTyreInflation(carId, 3)

    packetID = packetID + 1
    sharedmem.packetID = packetID
예제 #7
0
 def get_standings_position(self, identifier):
     if len(self.standings):
         p = [i for i, v in enumerate(self.standings) if v[0] == identifier]
         if len(p) > 0:
             return p[0] + 1
     return ac.getCarLeaderboardPosition(identifier)  # + 1
예제 #8
0
파일: acinfo.py 프로젝트: prunn/ACTV
 def onUpdate(self, sim_info, fl):
     self.session.setValue(sim_info.graphics.session)
     self.manageWindow()
     self.animate()
     if self.carsCount==0:
         self.carsCount = ac.getCarsCount()
     sessionTimeLeft=sim_info.graphics.sessionTimeLeft
     sim_info_status=sim_info.graphics.status
     self.currentVehicule.setValue(ac.getFocusedCar())        
     backupLaptime=0
     backupLastLapInPits=0
     if len(self.lapTimesArray) < self.carsCount:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap.append(Value(c))
             self.lapTimesArray.append(lapTimeStart(c,sessionTimeLeft,0)) 
     else:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap[x].setValue(c)
             if self.driversLap[x].hasChanged():
                 self.lapTimesArray[x].lap=self.driversLap[x].value
                 self.lapTimesArray[x].time=sessionTimeLeft
             if bool(ac.isCarInPitline(x)) or bool(ac.isCarInPit(x)):
                 self.lapTimesArray[x].lastpit=c
             if x == self.currentVehicule.value:
                 backupLaptime=self.lapTimesArray[x].time-sessionTimeLeft
                 self.lastLapStart = self.lapTimesArray[x].time
                 backupLastLapInPits = self.lapTimesArray[x].lastpit
     
                         
     currentVehiculeChanged=self.currentVehicule.hasChanged()
                 
     if currentVehiculeChanged or (self.fastestLapBorderActive and sessionTimeLeft < self.visible_end-2000):
         self.fastestLapBorderActive = False
         car = ac.getCarName(self.currentVehicule.value)        
         self.lbl_border.setBgColor(Colors.colorFromCar(car))           
         
     if sim_info_status == 2:
         #LIVE
         strOffset = "  "
         #self.nameOffset=14
         if self.session.value != 2 :
             #NOT RACE
             #qtime 
             self.fastestLap.setValue(fl)         
             bestlap = ac.getCarState(self.currentVehicule.value,acsys.CS.BestLap)
             isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
             LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
             if self.lastLap != LapCount:
                 self.lastLap = LapCount
                 self.firstLapStarted=False
                 if self.currentVehicule.value==0:
                     self.lastLapStart = sessionTimeLeft
             curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
             if curLapTime == 0 and backupLaptime > 0 and self.minLapCount > 0:
                 curLapTime = backupLaptime
             if curLapTime > 0:
                 self.firstLapStarted=True
             #if self.minLapCount == 0 and self.firstLapStarted and ((self.lastLapTime > curLapTime and curLapTime < 1000) or self.lastLapStart==10000):
             #    self.lastLapStart = sessionTimeLeft                  
             self.lastLapTime = curLapTime
                               
             if isInPit :
                 self.lastLapInPit = LapCount
                 self.lastTimeInPit = sessionTimeLeft
             if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated:
                 self.lastLapInvalidated = LapCount
             if isInPit and self.minLapCount == 0:
                 self.lastLapInvalidated = -1
             if self.sectorCount < 0:
                 self.sectorCount = sim_info.static.sectorCount    
             
             if self.fastestLap.value > 0:
                 for x in range(self.carsCount): 
                     c = ac.getCarState(x,acsys.CS.BestLap)
                     if self.fastestLap2.value == 0 or (c > 0 and c < self.fastestLap2.value):               
                         self.fastestLap2.setValue(c)
                         self.fastestLapSectors = ac.getLastSplits(x)
             else:
                 self.fastestLapSectors = [0,0,0,0,0,0]
                         
             #lapInvalidated = bool(ac.getCarState(0, acsys.CS.LapInvalidated))
             lapInvalidated = bool(self.lastLapInvalidated==LapCount)
             if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             #sector_delay = 5000
             # live or info      
             #ac.console("("+str(self.lastLapInPit)+" < "+str(LapCount)+" or "+str(self.minLapCount)+"==0) and not "+str(lapInvalidated)+" and ("+str(self.lastTimeInPit)+"==0 or "+str(self.lastTimeInPit)+" > "+str(self.lastLapStart)+")")            
             if ((self.lastLapStart < 0 and self.minLapCount > 0) or (self.minLapCount == 0 and lapInvalidated)) and self.session.value != 0:                    
                 self.lbl_driver_name_visible.setValue(0)
                 self.lbl_timing_visible.setValue(0)  
                 self.lbl_split.hideText()  
                 self.info_position.hide()
                 self.info_position_lead.hide()          
             elif (self.lastLapInPit < LapCount or self.minLapCount==0) and not lapInvalidated and (self.lastTimeInPit==0 or self.lastTimeInPit > self.lastLapStart or self.minLapCount==0) :
                 
                 if self.currentVehicule.value == 0:
                     sector = sim_info.graphics.currentSectorIndex
                 else:
                     sector = self.getSector()
                 
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)  
                 
                 #lapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
                 if self.currentVehicule.value == 0:
                     lastLap = sim_info.graphics.iLastTime
                 else: 
                     lastLap=0                       
                     lastSplits = ac.getLastSplits(self.currentVehicule.value)
                     for c in lastSplits:
                         lastLap+=c
                     if lastLap==0:
                         lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
                         
                 
                 traite=False
                 cur_splits = ac.getCurrentSplits(self.currentVehicule.value)
                 timeSplit=0
                 fastestSplit=0
                 i=0
                 showSplit=False
                 for c in cur_splits: 
                     if c > 0:
                         timeSplit+=c 
                         fastestSplit+=self.fastestLapSectors[i]
                         i+=1
                 fastestSplit_fin=fastestSplit
                 if i < self.sectorCount:
                     fastestSplit_fin+=self.fastestLapSectors[i]
                      
                 #Situation
                 for s in range(0,self.sectorCount):                    
                     if self.fastestLap.value > 0 and curLapTime > fastestSplit_fin - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_X, sector == s and
                         self.info_position.hide() 
                         self.nameOffset=self.rowHeight*14/36 #14
                         if self.sectorCount-1 == sector:
                             #LAST_SECONDS_OF_SECTOR_LAP,
                             self.lbl_split.setText(self.time_splitting(self.fastestLap.value,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             
                             showSplit=True
                         elif fastestSplit_fin > 0:
                             self.lbl_split.setText(self.time_splitting(fastestSplit_fin,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             showSplit=True
                         break
                     if sector == s + 1 and s + 1 <= self.sectorCount and curLapTime - timeSplit <= self.sector_delay and fastestSplit > 0 :
                         #SECTOR_X_FINISHED_BEGIN_SECTOR_Y    
                         self.nameOffset=self.rowHeight*14/36 #14            
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(timeSplit,"yes")) 
                         if fastestSplit < timeSplit:
                             self.lbl_split.setText("+"+self.time_splitting(timeSplit-fastestSplit,"yes")).setColor(Colors.yellow()).showText()
                         else:
                             self.lbl_split.setText("-"+self.time_splitting(fastestSplit-timeSplit,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         self.info_position.hide()
                         traite=True
                         break
                 
                 if not traite:
                     if self.sectorCount-1 == sector and self.fastestLap.value > 0 and curLapTime > self.fastestLap.value - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_LAP,
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime)) 
                         self.info_position.hide()
                         #self.lbl_split.setText(self.time_splitting(self.fastestLap,"yes") + strOffset).setVisible(1)
                     elif self.lastLapInvalidated!=LapCount-1 and ((self.lastLapInPit!=LapCount-1 and sector == 0) or (self.minLapCount==0)) and curLapTime <= self.sector_delay and lastLap > 0:
                         #LAP_FINISHED_BEGIN_NEW_LAP,                       
                         pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                         if pos == -1:
                             pos = self.getStandingsPosition(self.currentVehicule.value)                                
             
                         if pos > 1:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
                         else:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
                         self.info_position.setText(str(pos))
                         self.info_position.show()
                         
                         self.nameOffset=self.rowHeight*49/36 #49
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
                         if self.fastestLap.value < lastLap:
                             self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
                         else:                            
                             self.lbl_split.setText("-"+self.time_splitting(self.getBestLap()-lastLap,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         
                     else:
                         #OTHER
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
                         self.info_position.hide()
                         if not showSplit:
                             self.lbl_split.hideText()
                             self.info_position_lead.hide()
                 self.fastestLap.changed=False
             else :                    
                 self.info_position_lead.hide()                     
                 normalizedSplinePosition = ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition)
                 if normalizedSplinePosition <= 0.001:
                     normalizedSplinePosition=1
                 if sessionTimeLeft > 0 and self.minLapCount==1 and normalizedSplinePosition > 0.95 and not isInPit :          
                     self.lbl_driver_name_visible.setValue(1)
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_timing_visible.setValue(1)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                     self.lbl_timing_text.setValue(strOffset + "0.0") 
                     
                 elif lapInvalidated and self.lastLapInPit < LapCount and self.minLapCount > 0 :
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()  
                 elif bestlap > 0 :             
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)  
                      
                     if self.fastestLap.value < bestlap:
                         self.lbl_split.setText("+"+self.time_splitting(bestlap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()                           
                     else:                            
                         self.lbl_split.hideText()
                     
                     self.lbl_timing_text.setValue(strOffset + self.time_splitting(bestlap,"yes")) 
                                         
                     self.nameOffset=self.rowHeight*49/36 #49
                     #pos = sim_info.graphics.position
                     pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                     if pos == -1:
                         pos = self.getStandingsPosition(self.currentVehicule.value) 
                     if pos > 1:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                     else:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                     self.info_position.setText(str(pos)).show()   
                     self.lbl_position_text.setValue(str(pos))                
                         
                 elif isInPit :     
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                 else :
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)
                     if self.currentVehicule.value==0:
                         self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
                     else:
                         self.lbl_timing_text.setValue(strOffset + "Out Lap")
                     self.lbl_split.hideText()
                     self.info_position.hide() 
                  
             if curLapTime <= self.sector_delay and ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap) > 0 and backupLastLapInPits + 1 < ac.getCarState(x,acsys.CS.LapCount) and sessionTimeLeft < 0:
                 self.nameOffset=self.rowHeight*49/36 #49
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)
                 self.lbl_split.showText()
                 self.info_position.show() 
                 #time vis
             self.visibilityQualif()
                 
         else:
             ################ Race ################
             self.info_position_lead.hide() 
             self.lbl_split.hideText()
             #fastest lap
             completed=0
             for x in range(self.carsCount): 
                 c = ac.getCarState(x,acsys.CS.LapCount)
                 if c > completed:
                     completed=c
             if completed <=1:
                 self.race_fastest_lap.setValue(0)
             else:
                 for i in range(self.carsCount): 
                     bl=ac.getCarState(i,acsys.CS.BestLap)
                     l = ac.getCarState(i,acsys.CS.LapCount)
                     if bl > 0 and l > self.minLapCount and (self.race_fastest_lap.value == 0 or bl < self.race_fastest_lap.value):
                         self.race_fastest_lap.setValue(bl)
                         self.race_fastest_lap_driver.setValue(i)
                     
             if self.race_fastest_lap.hasChanged() and self.race_fastest_lap.value > 0:
                 self.fastestLapBorderActive = True
                 car = ac.getCarName(self.race_fastest_lap_driver.value)        
                 self.lbl_border.setBgColor(Colors.colorFromCar(car))            
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.race_fastest_lap_driver.value)))
                 self.nameOffset=self.rowHeight*14/36 #14
                 self.lbl_timing_text.setValue(strOffset + "Fastest Lap")
                 self.lbl_timing_visible.setValue(1)
                 self.info_position.hide() 
                 self.lbl_fastest_split.setText(self.time_splitting(self.race_fastest_lap.value,"yes")).showText()
                 
             elif currentVehiculeChanged:  
                 #driver info                  
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
                 self.nameOffset=self.rowHeight*49/36 #49
                 #pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                 pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
                 if pos > 1:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                 else:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                 self.info_position.setText(str(pos)).show() 
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
             elif self.visible_end == 0 or sessionTimeLeft < self.visible_end or sessionTimeLeft > 1800000:
                 self.lbl_driver_name_visible.setValue(0)
                 self.info_position.hide()
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
                 
             self.visibilityRace()
                 
     elif sim_info_status == 1 and self.session.value != 2:
         #Replay Qualif
         strOffset = "  "
         showSplit=False
         LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
         curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
         isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
         if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
         if isInPit:
             self.lbl_driver_name_visible.setValue(0)
             self.lbl_timing_visible.setValue(0)  
             self.lbl_split.hideText()  
             self.info_position.hide()
         elif curLapTime <= self.sector_delay and LapCount > 1:
             #show last lap
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value == 0:
                 lastLap = sim_info.graphics.iLastTime
             else: 
                 lastLap=0                       
                 lastSplits = ac.getLastSplits(self.currentVehicule.value)
                 for c in lastSplits:
                     lastLap+=c
                 if lastLap==0:
                     lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
             pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
             if pos == -1:
                 pos = self.getStandingsPosition(self.currentVehicule.value)                                
 
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
             self.info_position.setText(str(pos))
             self.info_position.show()
             self.nameOffset=self.rowHeight*49/36 #49
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
             if self.fastestLap.value < lastLap:
                 self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
             else:                            
                 self.lbl_split.setText("-"+self.time_splitting(self.fastestLap.old-lastLap,"yes")).setColor(Colors.green()).showText()
             self.info_position_lead.show()
             self.fastestLap.changed=False
         elif LapCount > self.minLapCount:
             #showTiming
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
             self.info_position.hide()
             if not showSplit:
                 self.lbl_split.hideText()
                 self.info_position_lead.hide()
         else:
             #showTireInfo
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value==0:
                 self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
             else:
                 self.lbl_timing_text.setValue(strOffset + "Out Lap")
             self.lbl_split.hideText()
             self.info_position.hide()            
         
         self.visibilityQualif()
             
             
         
     elif sim_info_status == 1 and self.session.value == 2:
         #Replay Race
         todo=1
         '''
         if currentVehiculeChanged:
             self.visible_end = sessionTimeLeft - 8000
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             self.nameOffset=self.rowHeight*49/36 #49
             pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
             self.info_position.setText(str(pos)).show() 
             self.lbl_timing_visible.setValue(0)
             self.lbl_fastest_split.hideText()
             
             if self.lbl_driver_name_visible.hasChanged():         
                 if self.lbl_driver_name_visible.value == 0:
                     self.lbl_driver_name.hide()
                     self.lbl_border.hide()
                 else:
                     self.lbl_driver_name.show()
                     self.lbl_border.show()
                 
             if self.lbl_timing_visible.hasChanged():         
                 if self.lbl_timing_visible.value == 0:
                     self.lbl_timing.hide()
                 else:
                     self.lbl_timing.show()
                     
             if self.lbl_driver_name_text.hasChanged():
                 self.lbl_driver_name.setText(self.lbl_driver_name_text.value)  
             if self.lbl_timing_text.hasChanged():
                 self.lbl_timing.setText(self.lbl_timing_text.value,hidden=bool(self.lbl_timing_height < 30)) 
         '''
     else:
         #REPLAY
         self.resetVisibility()
예제 #9
0
def acUpdate(deltaT):
    global enable_overtake, enable_lose, enable_win, enable_before_race, enable_pit
    global enable_suspense, enable_hotlap, suspense_laps, log
    global audio, overtake, iovertake, done, position, newposition
    global start_time, finish_time, count_overtake, bestlap, lastlap, hot_once, pit_once, lap
    global session, sessionTime, numberOfLaps, completedLaps, debuglabel, overflow, sound_player
    global isPlayingStartRace, isPlayingBeforeRace, isPlayingSuspense, isPlayingPit
    global isPlayingAfterRace, isPlayingOvertake, isPlayingHotlap
    global ar_once, ov_once, sus_once, sr_once, br_once, wait_a, debug, leader

    status = info.graphics.status
    session = info.graphics.session
    sessionTime = info.graphics.sessionTimeLeft
    # ac.log(log + "session time" + str(sessionTime))
    numberOfLaps = info.graphics.numberOfLaps
    completedLaps = info.graphics.completedLaps
    lenqueue = sound_player.lenQueue()
    lastlap = info.graphics.lastTime
    bestlap = info.graphics.bestTime
    pitlane = info.graphics.isInPitLane

    if ((sessionTime <= 0 and session <= 2) or session == 3) and lenqueue == 0 and (
                                isPlayingStartRace or
                                isPlayingBeforeRace or
                                isPlayingSuspense or
                                isPlayingAfterRace or
                                isPlayingOvertake or
                                isPlayingHotlap):
        wait_a += 1
        if lenqueue == 0 and wait_a == 100:
            isPlayingStartRace = isPlayingBeforeRace = isPlayingSuspense = \
                isPlayingAfterRace = isPlayingHotlap = isPlayingOvertake = isPlayingPit = False
            ac.log(log + "lenqueue reset")
            wait_a = 0

    # DEBUG INFOS
    if debug:
        ac.setText(labeldesc, "")
        ac.setText(debuglabel, "Session: " + repr(session) +
                   "\nNumber of laps: " + repr(numberOfLaps) +
                   "\nCompleted Laps: " + repr(completedLaps) +
                   "\nOvertakes: " + repr(count_overtake) +
                   "\nSession Time: " + repr(sessionTime) +
                   "\nLast lap: " + repr(lastlap) +
                   "\nBest lap: " + repr(bestlap) +
                   "\nPosition: " + repr(ac.getCarRealTimeLeaderboardPosition(0)) +
                   "\nLength queue: " + str(lenqueue) +
                   "\nLead position: " + repr(ac.getCarLeaderboardPosition(0)) +
                   "\nisPlayingStartRace: " + str(isPlayingStartRace) +
                   "\nisPlayingBeforeRace: " + str(isPlayingBeforeRace) +
                   "\nisPlayingSuspense: " + str(isPlayingSuspense) +
                   "\nisPlayingAfterRace: " + str(isPlayingAfterRace) +
                   "\nisPlayingPit: " + str(isPlayingPit) +
                   "\nisPlayingHotlap: " + str(isPlayingHotlap) +
                   "\nisPlayingOvertake: " + str(isPlayingOvertake))

    if overflow < 50:

        # DEBUG ONLY
        # overflow += 1

        if status == 2:
            if session == 2:  # Race sessions
                # ac.log(log + "Race session")
                if enable_before_race and not isPlayingBeforeRace and not br_once and sessionTime > 0:
                    ac.log(log + "Before race detected")
                    br_once = True
                    playBeforeRace()

                if enable_before_race and isPlayingBeforeRace and sessionTime <= 0:
                    stopPlaying()

                if enable_pit and isPlayingPit and not pit_once:
                    ac.log(log + "Pit detected")
                    pit_once = True
                    playPit()

                if enable_overtake and not isPlayingOvertake and not ov_once and sessionTime < 0 and (
                            numberOfLaps - completedLaps) != 0:
                    newposition = ac.getCarRealTimeLeaderboardPosition(0)
                    if position > newposition:
                        ac.log(log + "Overtake detected")
                        position = newposition
                        if done == 0:
                            start_time = time.perf_counter()
                            done = 1
                        overtake += 1
                        iovertake += 1
                        count_overtake += 1
                        if overtake == 2:
                            ac.log(log + "Overtake detected x2")
                            finish_time = time.perf_counter()
                            if finish_time - start_time < 30:
                                ac.log(log + "Epicness detected because 2 overtakes")
                                overtake = 0
                                playOvertake()
                                ov_once = True
                            else:
                                overtake = 0
                                done = 0
                        if iovertake == 3:
                            ac.log(log + "Overtake changes x2")
                            finish_time = time.perf_counter()
                            if finish_time - start_time < 30:
                                ac.log(log + "Epicness detected because 2 overtakes")
                                done = 0
                                iovertake = 0
                                overtake = 0
                                playOvertake()
                                ov_once = True
                            else:
                                done = 0
                                iovertake = 0
                                overtake = 0
                        if leader == 0 and ac.getCarRealTimeLeaderboardPosition(0) == 0:
                            ac.log(log + "Epicness detected because you are 1st")
                            overtake = 0
                            iovertake += 1
                            ov_once = True
                            playOvertake()
                    if position < newposition:
                        ac.log(log + "Undertake detected")
                        position = newposition
                        overtake = 0
                    if leader == 1 and ac.getCarRealTimeLeaderboardPosition(0) == 0:
                        ac.log(log + "Epicness detected because you are 1st (loop)")
                        overtake = 0
                        ov_once = True
                        playOvertake()

                if enable_suspense and not isPlayingSuspense and not sus_once and (
                            numberOfLaps - completedLaps) <= suspense_laps and (
                            numberOfLaps - completedLaps) != 0:
                    ac.log(log + "Suspense detected")
                    sus_once = True
                    playSuspense()
                if enable_win and not isPlayingAfterRace and not ar_once and ac.getCarRealTimeLeaderboardPosition(
                        0) == 0 and (
                            numberOfLaps - completedLaps) == 0:
                    ac.log(log + "Win detected")
                    ar_once = True
                    playAfterRace('win')
                if enable_lose and not isPlayingAfterRace and not ar_once and ac.getCarRealTimeLeaderboardPosition(
                        0) != 0 and (numberOfLaps - completedLaps) == 0:
                    ac.log(log + "Lose detected")
                    ar_once = True
                    playAfterRace('lose')

            if session == 1:  # Qualify session
                # ac.log(log + "Qualify session")
                if enable_suspense and not isPlayingSuspense and not sus_once and sessionTime < 120000:
                    ac.log(log + "Suspense detected")
                    sus_once = True
                    playSuspense()
                if enable_win and not isPlayingAfterRace and not ar_once and ac.getCarLeaderboardPosition(0) == 1:
                    ac.log(log + "Win detected")
                    ar_once = True
                    playAfterRace('win')

            if session == 3:  # Hotlap session
                if enable_hotlap:
                    if lastlap == bestlap and lap != lastlap and completedLaps > 1 \
                            and not hot_once and not isPlayingHotlap:
                        lap = lastlap
                        ac.log(log + "Hotlap detected")
                        hot_once = True
                        playHotlap()

    if overflow >= 50:
        stopPlaying()
        ac.log(log + "BSOD avoided. THERE WAS AN OVERFLOW")
        exit()