def reset_smart_tracking(self): self.__smart_tracking_fov_mix = 0 self.__t_smart_tracking = 0 self.__t_smart_tracking_2 = 1 self.__prev_smart_tracked_car = ac.getFocusedCar() self.__prev_smart_tracked_car_2 = ac.getFocusedCar() self.__cam_rot_momentum = 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)
def update(self): """Update session data.""" self.focused_car_id = ac.getFocusedCar() self.replay_time_multiplier = info.graphics.replayTimeMultiplier self.focused_car.set_id(self.focused_car_id) self.focused_car.update()
def is_last_camera(self): self.last_camera = 0 for self.i in range( self.get_n_cameras() ): if self.car_is_in_pitline[ac.getFocusedCar()]: if self.mode[self.active_mode][self.i].camera_pit: self.last_camera = self.i else: if not self.mode[self.active_mode][self.i].camera_pit: self.last_camera = self.i return self.last_camera == self.active_cam
def update_name(self, id): if id == ac.getFocusedCar(): ac.setVisible(self.highlightLabel, 1) else: ac.setVisible(self.highlightLabel, 0) if self.driverId == id: return # no need to update self.driverId = id self.driverName = ac.getDriverName(id) displayName = self.driverName.split()[-1][:3].upper() ac.setText(self.nameLabel, displayName) try: ac.setBackgroundTexture(self.teamLabel, FC.TEAM_COLORS[self.driverName]) except KeyError: ac.log("%s:Name Missing in teams.txt %s" % (FC.APP_NAME, self.driverName))
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 calcWorldPositions(self, delta): #we need to do all the calculations needed to draw this effectivly. self.nearcars = [] self.player = self.cars[ac.getFocusedCar()] self.player.isPlayer = True self.player.calcCar() playerVectorReversed = euclid.Vector2(self.player.currentVelocityVector.x * -1, self.player.currentVelocityVector.y * -1) # 绘车颜色方案 0: 玩家 1:玩家被套圈 2:其他车辆 3:套圈玩家的其他车车辆 4:其他车被玩家套圈 self.player.colorRecipe = 0 self.player.calcDrawingInformation(playerVectorReversed) for car in self.cars: car.calc(self.player) # 后面一段距离内是否有车快过玩家一圈 isPlayerBlueFlag = False if car.isVisible and car.playerDistance < helipicapewcar.distanceThreshold and car != self.player: car.isPlayer = False car.calcDrawingInformation(playerVectorReversed) car.calcAngleToPlayer(self.player.centerPositionGui) # 绘车颜色方案 0: 玩家 1:玩家被套圈 2:其他车辆 3:套圈玩家的其他车车辆 4:其他车被玩家套圈 car.colorRecipe = 2 if self.isRaceSession: if car.laps > self.player.laps: # 是快过玩家至少一圈的车 car.colorRecipe = 3 if car.splineposition < self.player.splineposition and self.player.splineposition - car.splineposition < 0.05: # 该车在玩家车后一小段距离 isPlayerBlueFlag = True elif car.laps < self.player.laps: # 是被玩家套圈的车 car.colorRecipe = 4 self.nearcars.append(car) #ac.log("helipicapew::near car {0}: {1}, local {2}, gui {3}".format(car.name, car.currentWorldPosition, car.relativePositionMeters, car.centerPositionGui)) if isPlayerBlueFlag: self.player.colorRecipe = 1 else: self.player.colorRecipe = 0
def update(self): """Update session data.""" # Update session attributes first, then car specific ones. self.focused_car_id = ac.getFocusedCar() self.status = info.graphics.status # Wind direction is provided based on compass directions in degrees. # North is 0 (or 360) degrees, East is 90, South is 180, West is 270. # Against convention, the variable points where the wind is going (rather than at the source) # It is converted to radians. self.wind_dir = ac.getWindDirection() * math.pi / 180 self.wind_speed = ac.getWindSpeed() self.air_temp = info.physics.airTemp self.road_temp = info.physics.roadTemp self.track_grip = info.graphics.surfaceGrip * 100 # Update car specific data self.focused_car.set_id(self.focused_car_id) self.focused_car.update()
def refresh(self, x, dt, interpolation, main_file): try: if not self.init: self.init = True try: self.load(main_file, "init") except Exception: pass for self.i in range(32): #max_cars if ac.isConnected(self.i) == 1: self.update_custom_car_info(interpolation, dt, self.i) self.prev_active_cam = self.active_cam for self.i in range( self.get_n_cameras() ): if not self.mode[self.active_mode][self.i].camera_pit: if x * ac.getTrackLength() < self.get_camera_in(self.i): self.active_cam = self.get_prev_camera(self.i) break else: self.active_cam = self.get_last_camera() #pit cameras if self.car_is_in_pitline[ac.getFocusedCar()]: for self.i in range( self.get_n_cameras() ): if self.mode[self.active_mode][self.i].camera_pit: if x * ac.getTrackLength() < self.get_camera_in(self.i): self.active_cam = self.get_prev_camera(self.i, "pit") break else: self.active_cam = self.get_last_camera("pit") except Exception as e: debug(e) self.active_cam = 0
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)
def on_update(self, sim_info): self.session.setValue(sim_info.graphics.session) session_time_left = sim_info.graphics.sessionTimeLeft sim_info_status = sim_info.graphics.status if sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0: self.session.setValue(-1) self.session.setValue(sim_info.graphics.session) self.manage_window() if self.carsCount == 0: self.carsCount = ac.getCarsCount() for x in range(self.carsCount): c = ac.getCarState(x, acsys.CS.SpeedKMH) if self.useMPH: mph = ac.getCarState(x, acsys.CS.SpeedMPH) if x == 0 and self.topSpeed.value < c: self.userTopSpeed.setValue(c) if self.useMPH: self.userTopSpeedMPH.setValue(mph) self.userTrap = ac.getCarState( x, acsys.CS.NormalizedSplinePosition) if self.relyOnEveryOne and self.topSpeed.value < c \ and ac.getCarState(x, acsys.CS.DriveTrainSpeed) > c / 10 \ and ac.getCarState(x, acsys.CS.Gas) > 0.9 \ and ac.getCarState(x, acsys.CS.RPM) > 2000: if c > 500: self.relyOnEveryOne = False self.topSpeed.setValue(self.userTopSpeed.value) if self.useMPH: self.topSpeedMPH.setValue(self.userTopSpeedMPH.value) self.trap = self.userTrap # ac.console("stop rely") else: self.topSpeed.setValue(c) if self.useMPH: self.topSpeedMPH.setValue(mph) self.trap = ac.getCarState( x, acsys.CS.NormalizedSplinePosition) elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c: self.topSpeed.setValue(c) if self.useMPH: self.topSpeedMPH.setValue(mph) self.trap = ac.getCarState(x, acsys.CS.NormalizedSplinePosition) self.current_vehicle.setValue(ac.getFocusedCar()) self.SpeedKMH.setValue( ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedKMH)) if self.useMPH: self.SpeedMPH.setValue( ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedMPH)) lap_count = ac.getCarState(self.current_vehicle.value, acsys.CS.LapCount) if self.curTopSpeed.value < self.SpeedKMH.value: self.curTopSpeed.setValue(self.SpeedKMH.value) if self.useMPH: self.curTopSpeedMPH.setValue(self.SpeedMPH.value) if self.current_vehicle.value == 0 and sim_info.physics.numberOfTyresOut >= 4: self.lastLapInvalidated = lap_count self.animate() if sim_info_status == 2: # Live is_in_pit = (bool(ac.isCarInPitline(self.current_vehicle.value)) or bool(ac.isCarInPit(self.current_vehicle.value))) if is_in_pit: self.lastLapInvalidated = lap_count position = ac.getCarState(self.current_vehicle.value, acsys.CS.NormalizedSplinePosition) if self.curTopSpeed.value < 500 and self.lastLapShown < lap_count \ and self.lastLapInvalidated < lap_count and self.widget_visible.value == 0 \ and position + 0.06 > self.trap > position - 0.08 \ and self.SpeedKMH.value < self.SpeedKMH.old - 0.6: # show and set timer 0.3 self.lastLapShown = lap_count self.widget_visible.setValue(1) if self.useMPH: speed_text = "%.1f mph | %.1f mph" % ( self.curTopSpeedMPH.value, self.topSpeedMPH.value) else: speed_text = "%.1f kph | %.1f kph" % ( self.curTopSpeed.value, self.topSpeed.value) self.time_start = session_time_left - 800 self.time_end = session_time_left - 14800 self.lbl_time_txt.setText(speed_text) # , hidden=True) self.lbl_title.set(y=self.row_height.value).show() self.lbl_title_txt.set(y=self.row_height.value + Font.get_font_x_offset()).show() elif self.time_start != 0 and self.time_start > session_time_left > self.time_end: self.lbl_title.set(y=0, animated=True).show() self.lbl_title_txt.set(y=0 + Font.get_font_x_offset(), animated=True).show() self.lbl_time.show() self.lbl_time_txt.show() self.lbl_border.show() elif self.time_end == 0 or session_time_left < self.time_end: self.reset_visibility() self.widget_visible.setValue(0) self.time_start = 0 self.time_end = 0 if self.widget_visible.hasChanged(): self.curTopSpeed.setValue(0) self.curTopSpeedMPH.setValue(0) # else: # self.reset_visibility() elif sim_info_status == 1: self.reset_visibility()
def CheckOffTrack(): global MaxNumberOfTyresOut, lastLap, bInvalidated, appWindow global sAppError, info global noOuts, isOut, noOutsCurrLap, lastTime, lastSessonTime if sAppError != "": ac.setTitle(appWindow, sAppError) else: #currentCar = 0 currentCar = ac.getFocusedCar() currentLap = ac.getCarState(currentCar, acsys.CS.LapCount) # currentLap = info.graphics.numberOfLaps currentTime = ac.getCarState(currentCar, acsys.CS.LapTime) # if currentTime < lastTime and lastLap > currentLap: currentSessonTime = info.graphics.sessionTimeLeft if currentSessonTime > lastSessonTime: # new session bInvalidated = False isOut = False noOuts = 0 noOutsCurrLap = 0 lastLap = -1 lastTime = -1.0 ac.setSize(appWindow, 200, 25) lastTime = currentTime lastSessonTime = currentSessonTime if lastLap < currentLap and currentTime > 0.05: # new lap bInvalidated = False noOutsCurrLap = 0 lastLap = currentLap if noOuts > 0: ac.setSize(appWindow, 200, 50) else: ac.setSize(appWindow, 200, 25) CurrNumberOfTyresOut = info.physics.numberOfTyresOut if CurrNumberOfTyresOut >= MaxNumberOfTyresOut: if not isOut: isOut = True noOuts += 1 noOutsCurrLap += 1 if currentLap > 0: ac.setSize(appWindow, 200, 75) else: ac.setSize(appWindow, 200, 50) if not bInvalidated and currentCar == 0: # only for ourself, not another car bInvalidated = True ac.ext_markLapAsSpoiled() # CSP function if CurrNumberOfTyresOut > 1: ac.setTitle( appWindow, " OFF track: " + str(CurrNumberOfTyresOut) + " wheels" + getAddenum(noOuts, currentLap) + getAddenum2(noOutsCurrLap, currentLap) ) # + "\n" + str(currentLap) + "\n" + str(currentTime)) else: ac.setTitle( appWindow, " OFF track: " + str(CurrNumberOfTyresOut) + " wheel" + getAddenum(noOuts, currentLap) + getAddenum2(noOutsCurrLap, currentLap) ) # + "\n" + str(currentLap) + "\n" + str(currentTime)) else: isOut = False addenum = "" if noOuts > 0: addenum = "\n " + str(noOuts) + " cut(s) already" ac.setTitle( appWindow, " ON track" + getAddenum(noOuts, currentLap) + getAddenum2(noOutsCurrLap, currentLap) ) # + "\n" + str(currentLap) + "\n" + str(currentTime))
def getFocusedCar(): return ac.getFocusedCar()
def update_smart_tracking_values(self, ctt, data, interpolation, info, the_x, dt): try: self.camera_in = data.mode[data.active_mode][data.active_cam].camera_in self.camera_out = data.get_camera_out() self.car_id = ac.getFocusedCar() self.opponent = self.get_closest_opponent(self.car_id, interpolation, x, data) #------------------------------------------------------------------- #VERIFY SECOND CAR #change opponent only if is the closest one for x amount of time if self.opponent != self.__prev_smart_tracked_car_2: self.__t_smart_tracking_2 += (dt * info.graphics.replayTimeMultiplier / 2) if self.__t_smart_tracking_2 > 1 and self.__t_smart_tracking == 0: self.__t_smart_tracking_2 = 0 self.__prev_smart_tracked_car_2 = self.opponent else: self.opponent = self.__prev_smart_tracked_car_2 else: self.__t_smart_tracking_2 = 0 self.__prev_smart_tracked_car_2 = self.opponent #dark magic - prevent jumping between opponents during transition if self.__prev_smart_tracked_car != self.opponent or self.__t_smart_tracking > 0: if self.__locked_smart_tracked_car == None: self.__locked_smart_tracked_car = self.opponent else: self.opponent = self.__locked_smart_tracked_car self.__t_smart_tracking += (dt * info.graphics.replayTimeMultiplier / self.transition) if self.__t_smart_tracking > 1: self.__prev_smart_tracked_car = self.__locked_smart_tracked_car self.__locked_smart_tracked_car = None self.__t_smart_tracking = 0 #------------------------------------------------------------------- #FIND AND VERIFY LAST CAR OUT IN CAMERA SECTOR self.last_car_out = {"id": None, "duration": None, "pos_expected": None} for self.i in range(32): #max_cars if ac.isConnected(self.i) == 1: if data.get_car_is_out(self.i)["status"] == True: if self.last_car_out["id"] == None: self.last_car_out["id"] = self.i self.last_car_out["duration"] = data.get_car_is_out(self.i)["duration"] self.last_car_out["pos_expected"] = data.get_car_is_out(self.i)["pos_expected"] else: if self.last_car_out["duration"] > data.get_car_is_out(self.i)["duration"] and data.get_car_is_out(self.i)["duration"] > 1: self.last_car_out["id"] = self.i self.last_car_out["duration"] = data.get_car_is_out(self.i)["duration"] self.last_car_out["pos_expected"] = data.get_car_is_out(self.i)["pos_expected"] #------------------------------------------------------------------- #CAR IS CLOSE #if self.last_car_out["id"] == None: #if self.car_id = #CAR OUT #self.__car_out = self.last_car_out["id"] # self.__smart_tracking_fov_mix = 1 # self.__smart_tracking_cam_rot_to_track = self.calculate_cam_rot_to_point(ctt, self.last_car_out["pos_expected"]) # self.__smart_tracking_cam_rot_to_car_out = self.calculate_cam_rot_to_tracking_car(ctt, data, info, self.__car_out) * vec3(0.5, 0.5, 0.5) + self.__smart_tracking_cam_rot_to_track * vec3(0.5, 0.5, 0.5) # self.__smart_tracking_fov = self.calculate_fov(ctt, self.cam_pos_2d, self.car_pos_2d, vec(self.last_car_out["pos_expected"].x, self.last_car_out["pos_expected"].y)) self.__smart_tracking_x = the_x self.__smart_tracking_cam_rot = self.calculate_cam_rot_to_tracking_car(ctt, data, info, ac.getFocusedCar(), dt) self.__smart_tracking_fov = ctt.get_fov() except Exception as e: debug(e)
def calculate_cam_rot_to_tracking_car(self, ctt, data, info, car_id, dt): try: self.car_pos = ac.getCarState(car_id, acsys.CS.WorldPosition) self.__avg_car_pos = vec3() # self.interval = (1/100) # if self.__t_cars_position < self.interval: # self.__t_cars_position += dt * info.graphics.replayTimeMultiplier # else: # self.__t_cars_position = 0 for self.i in range(self.__tracking_smoothness-1, -1, -1): if self.i > 0: #if self.__t_cars_position == 0: self.__tracked_car_positions[self.i][car_id].x = self.__tracked_car_positions[self.i-1][car_id].x self.__tracked_car_positions[self.i][car_id].y = self.__tracked_car_positions[self.i-1][car_id].y self.__tracked_car_positions[self.i][car_id].z = self.__tracked_car_positions[self.i-1][car_id].z else: self.__tracked_car_positions[0][car_id].x = self.car_pos[0] self.__tracked_car_positions[0][car_id].y = self.car_pos[2] self.__tracked_car_positions[0][car_id].z = self.car_pos[1] self.__avg_car_pos.x += self.__tracked_car_positions[self.i][car_id].x self.__avg_car_pos.y += self.__tracked_car_positions[self.i][car_id].y self.__avg_car_pos.z += self.__tracked_car_positions[self.i][car_id].z self.__avg_car_pos.x /= self.__tracking_smoothness self.__avg_car_pos.y /= self.__tracking_smoothness self.__avg_car_pos.z /= self.__tracking_smoothness self.__pred_car_pos = vec3() self.__pred_car_pos.x = self.__tracked_car_positions[0][car_id].x + (self.__tracked_car_positions[0][car_id].x - self.__avg_car_pos.x) self.__pred_car_pos.y = self.__tracked_car_positions[0][car_id].y + (self.__tracked_car_positions[0][car_id].y - self.__avg_car_pos.y) self.__pred_car_pos.z = self.__tracked_car_positions[0][car_id].z + (self.__tracked_car_positions[0][car_id].z - self.__avg_car_pos.z) self.cam_pos = vec3( ctt.get_position(0), ctt.get_position(1), ctt.get_position(2) ) #camera rot raw momentum for offset shake self.x = self.car_pos[0] - self.cam_pos.x self.y = self.car_pos[2] - self.cam_pos.y self.z = self.car_pos[1] - self.cam_pos.z self.xy = math.sqrt((self.x*self.x) + (self.y*self.y)) self.heading = math.atan2( self.x, self.y ) + math.pi/2 self.pitch = math.atan2( self.z, self.xy ) if car_id == ac.getFocusedCar(): if self.__t < (1/60) and info.graphics.replayTimeMultiplier < 0.9: self.__t += dt * info.graphics.replayTimeMultiplier else: for self.i in range(self.__n_prev_cam_heading - 1, -1, -1): if self.i > 0: self.__prev_cam_heading[self.i] = self.__prev_cam_heading[self.i - 1] else: if self.__prev_cam_heading[0] == None: for self.j in range(self.__n_prev_cam_heading): self.__prev_cam_heading[self.j] = self.heading else: self.__prev_cam_heading[0] = self.heading self.__t = 0 if data.get_offset() < 0: self.x = (self.__pred_car_pos.x * self.__get_offset(data, info, dt) + self.car_pos[0] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.x self.y = (self.__pred_car_pos.y * self.__get_offset(data, info, dt) + self.car_pos[2] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.y self.z = (self.__pred_car_pos.z * self.__get_offset(data, info, dt) + self.car_pos[1] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.z else: self.x = (self.__avg_car_pos.x * self.__get_offset(data, info, dt) + self.car_pos[0] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.x self.y = (self.__avg_car_pos.y * self.__get_offset(data, info, dt) + self.car_pos[2] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.y self.z = (self.__avg_car_pos.z * self.__get_offset(data, info, dt) + self.car_pos[1] * (1 - self.__get_offset(data, info, dt))) - self.cam_pos.z self.xy = math.sqrt((self.x*self.x) + (self.y*self.y)) self.heading = math.atan2( self.x, self.y ) + math.pi/2 self.pitch = math.atan2( self.z, self.xy ) self.roll = ctt.get_roll() return vec3(self.pitch, self.roll, self.heading) except Exception as e: debug(e)
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
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()
def onUpdate(self, sim_info): self.session.setValue(sim_info.graphics.session) sessionTimeLeft=sim_info.graphics.sessionTimeLeft sim_info_status=sim_info.graphics.status if (sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0) or sessionTimeLeft >= 1800000: self.resetVisibility() self.time_end = 0 self.manageWindow() if self.carsCount==0: self.carsCount = ac.getCarsCount() for x in range(self.carsCount): c = ac.getCarState(x,acsys.CS.SpeedKMH) if x==0 and self.topSpeed.value < c: self.userTopSpeed.setValue(c) self.userTrap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) if self.relyOnEveryOne and self.topSpeed.value < c and ac.getCarState(x,acsys.CS.DriveTrainSpeed) > c/10 and ac.getCarState(x,acsys.CS.Gas) > 0.9 and ac.getCarState(x,acsys.CS.RPM) > 2000: if c > 500: self.relyOnEveryOne=False self.topSpeed.setValue(self.userTopSpeed.value) self.trap = self.userTrap #ac.console("stop rely") #ac.log("stop rely") else: self.topSpeed.setValue(c) #ac.console(str(c) + "-"+str(x)+"-rpm:"+str(ac.getCarState(x,acsys.CS.RPM))+"-Gas:"+str(ac.getCarState(x,acsys.CS.Gas))+"-Gear:"+str(ac.getCarState(x,acsys.CS.Gear))+"-DriveTrainSpeed:"+str(ac.getCarState(x,acsys.CS.DriveTrainSpeed))) self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c: self.topSpeed.setValue(c) self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) self.currentVehicule.setValue(ac.getFocusedCar()) self.SpeedKMH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedKMH)) self.SpeedMPH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedMPH)) LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount) if self.curTopSpeed.value < self.SpeedKMH.value: self.curTopSpeed.setValue(self.SpeedKMH.value) self.curTopSpeedMPH.setValue(self.SpeedMPH.value) if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated: self.lastLapInvalidated = LapCount self.animate() if sim_info_status == 2: if self.session.value <= 2 : #Qual-Practise every time #isInPit = self.currentVehicule.value==0 and bool(sim_info.physics.pitLimiterOn) isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value))) if isInPit : self.lastLapInPit = LapCount if self.lastLapInPit < LapCount and self.curTopSpeed.value < 500 and self.lastLapShown < LapCount and self.lastLapInvalidated < LapCount and self.widget_visible.value == 0 and self.trap < ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) + 0.06 and self.trap > ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) - 0.08 and self.SpeedKMH.value < self.SpeedKMH.old - 0.6: #show and set timer 0.3 self.lastLapShown=LapCount self.widget_visible.setValue(1) if self.useMPH: self.speedText="%.1f mph"%(self.curTopSpeedMPH.value) else: self.speedText="%.1f kph"%(self.curTopSpeed.value) self.time_end = sessionTimeLeft - 9000 self.lbl_title.setText("S",hidden=True) self.lbl_time.setText(self.speedText,hidden=True) self.lbl_time.show() self.lbl_border.show() self.lbl_title.show() elif self.time_end == 0 or sessionTimeLeft < self.time_end: self.lbl_time.hide() self.lbl_border.hide() self.lbl_title.hide() self.widget_visible.setValue(0) self.time_end=0 if self.widget_visible.hasChanged(): self.curTopSpeed.setValue(0) self.curTopSpeedMPH.setValue(0) else: self.resetVisibility() elif sim_info_status == 1: self.resetVisibility()