GE Lua Documentation

Press F to search!

changeState

Definition


-- @/lua/ge/extensions/scenario/scenarios.lua:188

local function changeState(newState)
  if not scenario then return end

  log('D', logTag, 'changeState: ' .. tostring(newState))

  scenario.state = newState

  if scenario.state == 'pre-start' then
    -- Collisions should always be enabled during scenarios
    -- log('I', logTag, 'enabling dynamicCollision...')
    be:setDynamicCollisionEnabled(true)

    needFreezeVehicles = true
    checkExtensions = true
    if scenario.showCountdown == nil then scenario.showCountdown = true end
    scenario.showCountdown = scenario.showCountdown and not scenario.rollingStart
    scenario.pooledResults = {}
    scenario.preStartStage = 0
  elseif scenario.state == 'pre-running' then
    -- scenario is still in introduction phase
    guihooks.trigger('ScenarioResetTimer')
    guihooks.trigger('setQuickRaceMode')
    guihooks.trigger("HotlappingResetApp")
    guihooks.trigger('ScenarioNotRunning')

    scenario.raceState = ''
    scenario.currentLap = 0
    scenario.timerActive = true

    raceMarker.init()
    if scenario_raceUI then
      scenario_raceUI.initialise(scenario)
    end

    if scenario_raceGoals then scenario_raceGoals.initialiseGoals() end
    scenario_waypoints.initialise()

    freezeAll(1)
    commands.setGameCamera()
  elseif scenario.state == 'deferredRunning' then
    changeState('running')
  elseif scenario.state == 'running' and scenario.raceState == '' then
    finalizePreRunning()

    local lastCameraMode = scenario.lastModeName
    if not lastCameraMode then
      lastCameraMode = 'orbit'
    end
    core_camera.setByName(0, lastCameraMode) -- change back to the correct camera just before the countdown starts
    if lastCameraMode ~= 'relative' then
      core_camera.resetCamera(0)
    end

    showIntroPrefab(false)

    -- the scenario just entered running state
    scenario.raceState = 'countdown'

    -- start the countdown
    scenario.timer = 0

     -- this states will be removed after countdown
    if not scenario.showCountdown then
      scenario.countDownTime = 1.5
    else
      scenario.countDownTime = 3.5
    end

    scenario.countDownShowed = false

    initVehicleAIState()

    extensions.hook("onRaceInit")
  elseif scenario.state == 'finished' then
    extensions.hook('onScenarioFinished', scenario)
  elseif scenario.state == 'post' then
    -- scenario just finished
    scenario.raceState = 'done'
    --raceMarker.hide(true)
  end

  extensions.hook('onScenarioChange', scenario)
end

Callers

@/lua/ge/extensions/tech/techCore.lua
  if isBlocking('restartScenario') then
    scenario_scenarios.changeState('running')
    scenario.showCountdown = false
  if scenario then -- 'normal' scenario loading (not flowgraph)
    scenario_scenarios.changeState('running')
  end
@/lua/ge/extensions/scenario/scenarios.lua
  elseif scenario.state == 'deferredRunning' then
    changeState('running')
  elseif scenario.state == 'running' and scenario.raceState == '' then
  if scenario.state ~= 'finished' and scenario.state ~= 'post' then
    changeState('finished')
    endRaceCountdown = countDownTime or scenario.endCountDownTime or 3;

  changeState('pre-start')
end
  scenario.restartStage = 0
  changeState('restart')
end
    -- start the race subsystem
    changeState('pre-running')
  end
    log('D', logTag, 'trying to start scenario')
    changeState('running')
  elseif state == 'play' and scenario.state == 'physicsPaused' and scenarioStateAtPauseEvent == 'pre-running' then
  scenario.result = finalResult
  changeState('post')

    changeState('pre-start')
    extensions.hook('onScenarioRestarted', scenario)
    if scenario.state ~= 'restart' then
      changeState(scenarioStateAtPauseEvent)
    end
    scenarioStateAtPauseEvent = scenario.state
    changeState('physicsPaused')
  end