def acUpdate(delta_t):
    global last_calculated, last_posted
    global spinner_calculation_interval, spinner_posting_interval
    global label_names, label_track_progress, label_penalties, label_last_message
    global turn_gen, penalties

    CALCULATION_INTERVAL = ac.getValue(spinner_calculation_interval) / 1000
    POSTING_INTERVAL = ac.getValue(spinner_posting_interval) / 1000

    if (time.clock() - last_calculated) > CALCULATION_INTERVAL:
        last_calculated = time.clock()

        progresses = get_progresses()
        penalties = calculate_penalties(progresses)

        ac.setText(
            label_track_progress, "Track progresses: {}".format(
                [round(float(i), 2) for i in progresses]))
        ac.setText(
            label_penalties, "Penalty percentages: {}".format(
                [round(float(i), 2) for i in penalties]))

    if (time.clock() - last_posted) > POSTING_INTERVAL:
        p_type, target = next(turn_gen)

        if ac.isConnected(target):
            last_posted = time.clock()
            msg = create_msg(p_type, target, penalties)

            ac.sendChatMessage(msg)
            ac.setText(label_last_message,
                       "Last message posted: {}".format(msg))
Пример #2
0
def getDriverInformation(detectionArea):
    global labelStorage, appPosX, appPosY, spinner_y_offset, fov_setting
    triangle = Triangle(detectionArea[0], detectionArea[1], detectionArea[2])
    setLabel = 0
    for x in range(ac.getCarsCount()):
        posX, posZ, posY = ac.getCarState(x, acsys.CS.WorldPosition)
        if triangle.isInside((posX, posY)) and x != 0:
            vect_x = posX - detectionArea[0][0]
            vect_y = posY - detectionArea[0][1]
            distance = math.sqrt(math.pow(vect_x, 2) + math.pow(vect_y, 2))
            newPosition = getRenderPosition(x, detectionArea, (posX, posY))
            ac.setText(labelStorage[setLabel], ac.getDriverName(x))
            fov_angle = ac.getValue(fov_setting)
            xPos = (((newPosition * windowSizeX) / fov_angle) - appPosX)
            yOffset = ac.getValue(spinner_y_offset)
            yPos = (((windowSizeY / 2) - 20) - appPosY) + int(yOffset)
            fontSize = (10 *
                        (1 /
                         (distance / 100))) * (ac.getValue(scale_factor) / 10)
            ac.setPosition(labelStorage[setLabel], xPos, yPos)
            ac.setFontSize(labelStorage[setLabel], fontSize)
            setLabel += 1

    for z in range(ac.getCarsCount() - setLabel):
        ac.setText(labelStorage[setLabel + z], "")
Пример #3
0
def FuelEvent(x):
    global FuelSelection,amount,Gas

    amount = ac.getValue(FuelSelection)
    ac.setText(label3,"{}".format(round(amount)))
    Gas = ac.getText(label3)
    WriteData()
Пример #4
0
def onVolumeChanged(value):
    global audio_volume, VolumeSpinner, sound_player
    audio_volume = int(ac.getValue(VolumeSpinner))
    sound_player.set_volume(audio_volume / 100)
    config['Audio']['volume'] = str(audio_volume)
    setDescription(VolumeSpinner, '''
    Set the overall volume of
    the app.''')
def calculate_penalties(progresses):
    global spinner_smoothing, spinner_nonlinearity

    SMOOTHING = ac.getValue(spinner_smoothing) / 100
    NONLINEARITY = ac.getValue(spinner_nonlinearity)

    prog_min = min(progresses)
    prog_max = max(progresses)

    advantages = [p - prog_min for p in progresses]
    scale = max(0.001, prog_max - prog_min)
    dampen = min(1.0, (prog_max - prog_min) / SMOOTHING)

    raw_penalties = [dampen * (a / scale) for a in advantages]
    nonlinear_penalties = [p**NONLINEARITY for p in raw_penalties]

    return nonlinear_penalties
Пример #6
0
def FuelEvent(x):
    global Fill, FuelSelection, Gas, FuelAdd, FuelMax, Resolution

    Gas = int(ac.getValue(FuelSelection))

    if Gas == FuelMax:
        ac.setBackgroundTexture(Fill, "apps/python/BoxRadio/img/fuel_fill_ON.png")
    else:
        ac.setBackgroundTexture(Fill, "apps/python/BoxRadio/img/fuel_fill_OFF.png")
Пример #7
0
def FuelEvent(x):
    global Fill, FuelSelection, Gas, FuelAdd, FuelMax, Resolution

    Gas = int(ac.getValue(FuelSelection))

    if Gas == FuelMax:
        ac.setBackgroundTexture(Fill,
                                "apps/python/BoxRadio/img/fuel_fill_ON.png")
    else:
        ac.setBackgroundTexture(Fill,
                                "apps/python/BoxRadio/img/fuel_fill_OFF.png")
Пример #8
0
def onSoundPackChanged(x):
    global audiolist, audiolabel, config, audio, SoundPackSpinner
    audio = audiolist[int(ac.getValue(SoundPackSpinner))]
    ac.setText(audiolabel, audio)
    config['Audio']['source'] = str(audio)
    initSoundPack(audio)
    setDescription(SoundPackSpinner, '''
      Select the audio set that you
      would like to use.
      This refers to a folder in the
      app's /SoundPacks/ directory.''')
Пример #9
0
def getDetectionArea():
    global fov_setting
    posX, posZ, posY = ac.getCarState(0, acsys.CS.WorldPosition)
    rads = getRotation(0)
    fov_angle = ac.getValue(fov_setting)
    PointTopLeftX, PointTopLeftY = move_vector(
        (posX, posY + 200), rads - math.radians(fov_angle / 2), (posX, posY))
    PointTopRightX, PointTopRightY = move_vector(
        (posX, posY + 200), rads + math.radians(fov_angle / 2), (posX, posY))

    return ((posX, posY), (PointTopLeftX, PointTopLeftY), (PointTopRightX,
                                                           PointTopRightY))
def create_msg(p_type, target, penalties):
    global spinner_ballast
    global spinner_restrictor

    MAX_BST = ac.getValue(spinner_ballast)
    MAX_RST = ac.getValue(spinner_restrictor)

    p_pct = penalties[target]

    if p_type == 'ballast':
        value = int(p_pct * MAX_BST)
    elif p_type == 'restrictor':
        value = int(p_pct * MAX_RST)

    if USE_GRID_ID_CONVERSION:
        driver_name = DRIVER_NAMES[target]
        target = GRID_IDS.get(driver_name, "NA")

    msg = "/{} {} {}".format(p_type, target, value)

    return msg
Пример #11
0
def onRaceLapsChangedListener(*args):
    global raceLapsSpinner, raceLaps, shownCalcData

    raceLaps = ac.getValue(raceLapsSpinner)
    updateFuelEstimate()
Пример #12
0
def onTimedRaceMinutesChangedListener(*args):
    global timedRaceMinutesSpinner, timedRaceMinutes, shownCalcData

    timedRaceMinutes = ac.getValue(timedRaceMinutesSpinner)
    updateFuelEstimate()
Пример #13
0
 def value(self):
     if self.has_id:
         return ac.getValue(self.id)
     return self._value
Пример #14
0
def onEnableWin(x):
    global enable_win
    value = int(ac.getValue(Win))
    enable_win = value
    config['Victory']['active'] = str(value)
Пример #15
0
def onEnableBeforeRace(x):
    global enable_before_race
    value = int(ac.getValue(Beforerace))
    enable_before_race = value
    config['Before Race']['active'] = str(value)
Пример #16
0
def onEnableOverTake(x):
    global enable_overtake
    value = int(ac.getValue(Overtake))
    enable_overtake = value
    config['Overtake']['active'] = str(value)
Пример #17
0
def onEnableLose(x):
    global enable_lose
    value = int(ac.getValue(Lose))
    enable_lose = value
    config['Lose']['active'] = str(value)
Пример #18
0
def onEnablePit(x):
    global enable_pit
    value = int(ac.getValue(Pit))
    enable_pit = value
    config['Pit']['active'] = str(value)
Пример #19
0
def onEnableHotlap(x):
    global enable_hotlap
    value = int(ac.getValue(Hotlap))
    enable_hotlap = value
    config['Hotlap']['active'] = str(value)
Пример #20
0
 def gValue(self):
     return ac.getValue(self.dt)
Пример #21
0
 def getValue(self):
     return ac.getValue(self.spinner)
Пример #22
0
def onEnableSuspense(x):
    global enable_suspense
    value = int(ac.getValue(Suspense))
    enable_suspense = value
    config['Suspense']['active'] = str(value)