Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Jun 11, 2024
1 parent 602280a commit a372783
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ local function cellChangedCallback(e)
-- delete all vehicles
for id, s in pairs(GTrackingManager.getInstance().trackingList) do
local vehicle = s ---@cast vehicle CVehicle
vehicle.markForDelete = true
-- only mark vehicles that are in onspline ai state
if vehicle.aiStateMachine and vehicle:isOnSpline() then
vehicle.markForDelete = true
end
end

return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ function TrackingManager:doCull()
-- only cull vehicles that are in onspline ai state
if vehicle.aiStateMachine and vehicle.aiStateMachine.currentState.name == CAiState.ONSPLINE then
if not vehicle:GetRootBone() then
log:warn("No root bone %s", s:Id())
log:debug("doCull No root bone %s", s:Id())
table.insert(toremove, s)
goto continue
end

local d = tes3.player.position:distance(vehicle.last_position)
if d > self.cullRadius * 8192 then
log:debug("Culled out of distance %s", s:Id())
log:debug("doCull Culled out of distance %s", s:Id())
table.insert(toremove, s)
goto continue
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ end
---@return boolean
function CAiState.ToNone(ctx)
local vehicle = ctx.scriptedObject ---@cast vehicle CVehicle
return not vehicle.routeId and not vehicle.playerRegistered and not vehicle:isPlayerInGuideSlot()
return not vehicle.routeId and not vehicle:isPlayerInGuideSlot()
end

---transition to ONSPLINE state if routeId is not nil
---@param ctx any
---@return boolean?
function CAiState.ToOnSpline(ctx)
local vehicle = ctx.scriptedObject ---@cast vehicle CVehicle
return vehicle.routeId and not vehicle.playerRegistered and not vehicle:isPlayerInGuideSlot()
return vehicle.routeId and not vehicle:isPlayerInGuideSlot() and not vehicle.playerRegistered
end

---transition to player steer state if player is in guide slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ local function uiShowRestMenuCallback(e)
-- then to destination
-- this pushes the AI statemachine
vehicle.routeId = nil

timer.start({
type = timer.simulate,
duration = 1,
callback = (function()
tes3.fadeIn()

lib.teleportToClosestMarker()

vehicle:EndPlayerTravel()

vehicle:Delete()
GPlayerVehicleManager.getInstance().trackedVehicle = nil
end)
})
end
end)
})
Expand Down Expand Up @@ -212,10 +227,26 @@ function PlayerTravelState:update(dt, scriptedObject)
local spline = GRoutesManager.getInstance().routes[vehicle.routeId]
if spline == nil then
vehicle.routeId = nil
end
if vehicle.splineIndex > #spline then
elseif vehicle.splineIndex > #spline then
-- reached end of route
vehicle.routeId = nil

tes3.fadeOut()

timer.start({
type = timer.simulate,
duration = 1,
callback = (function()
tes3.fadeIn()

lib.teleportToClosestMarker()

vehicle:EndPlayerTravel()

vehicle:Delete()
GPlayerVehicleManager.getInstance().trackedVehicle = nil
end)
})
end

-- handle player leaving vehicle
Expand All @@ -238,23 +269,6 @@ function PlayerTravelState:exit(scriptedObject)
event.unregister(tes3.event.activate, activateCallback)
event.unregister(tes3.event.keyDown, keyDownCallback)
event.unregister(tes3.event.uiShowRestMenu, uiShowRestMenuCallback)

tes3.fadeOut()

timer.start({
type = timer.simulate,
duration = 1,
callback = (function()
tes3.fadeIn()

lib.teleportToClosestMarker()

vehicle:EndPlayerTravel()

vehicle:Delete()
GPlayerVehicleManager.getInstance().trackedVehicle = nil
end)
})
end

return PlayerTravelState
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ local function CalculatePositions(vehicle, nextPos)
virtualpos = rootBone.worldTransform * tes3vector3.new(-1204, 1024, nextPos.z)
end
end
else
lib.log:debug("CalculatePositions %s: rootBone is nil", vehicle:Id())
end

-- calculate diffs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ end

--#region CVehicle methods

function CVehicle:isOnSpline()
return self.aiStateMachine and self.aiStateMachine.currentState and
self.aiStateMachine.currentState.name == CAiState.ONSPLINE
end

--- StartPlayerSteer is called when the player starts steering
function CVehicle:StartPlayerSteer()
log:trace("StartPlayerSteer %s", self.id)
Expand Down Expand Up @@ -222,6 +227,9 @@ end
---@param routeId string
function CVehicle:StartPlayerTravel(guideId, routeId)
log:debug("StartPlayerTravel %s", self.id)
log:debug("AI state: %s", self.aiStateMachine.currentState.name)

self:Attach()

-- these push the AI statemachine
self.playerRegistered = true
Expand Down Expand Up @@ -375,11 +383,23 @@ end
-- player is within the surface of the mount
---@return boolean
function CVehicle:isPlayerInMountBounds()
if not self.referenceHandle:valid() then
return false
end

if not self.referenceHandle:getObject() then
return false
end

local mount = self.referenceHandle:getObject()
local bbox = mount.object.boundingBox

if not bbox then
return false
end

local inside = true
local volumeHeight = 200
local bbox = mount.object.boundingBox

local pos = tes3.player.position
local surfaceOffset = self.slots[1].position.z
Expand Down Expand Up @@ -434,7 +454,7 @@ end
function CVehicle:UpdateSlots(dt)
local rootBone = self:GetRootBone()
if rootBone == nil then
log:warn("UpdateSlots %s: rootBone is nil", self:Id())
log:debug("UpdateSlots %s: rootBone is nil", self:Id())
return
end

Expand Down Expand Up @@ -554,12 +574,12 @@ function CVehicle:UpdateSlots(dt)
if self.clutter then
for index, clutter in ipairs(self.clutter) do
if clutter.handle == nil then
log:warn("UpdateSlots %s: clutter handle is nil", self:Id())
log:debug("UpdateSlots %s: clutter handle is nil", self:Id())
end

if clutter.handle and clutter.handle:valid() then
if not clutter.handle:valid() then
log:warn("UpdateSlots %s: clutter handle is invalid", self:Id())
log:debug("UpdateSlots %s: clutter handle is invalid", self:Id())
end

clutter.handle:getObject().position = rootBone.worldTransform *
Expand Down Expand Up @@ -638,8 +658,12 @@ end
-- update player collision
---@param rootBone niNode?
function CVehicle:UpdatePlayerCollision(rootBone)
local isInTravelState = self.aiStateMachine.currentState.name == CAiState.PLAYERTRAVEL
local isInSteerState = self.aiStateMachine.currentState.name == CAiState.ONSPLINE
local playerCanFreeMove = isInSteerState or (isInTravelState and GPlayerVehicleManager.getInstance().free_movement)

-- check if player is in freemovement mode
if rootBone and tes3.player.tempData.itpsl then
if self.hasFreeMovement and playerCanFreeMove and rootBone and tes3.player.tempData.itpsl then
-- this is needed to enable collisions :todd:
tes3.dataHandler:updateCollisionGroupsForActiveCells {}
self.referenceHandle:getObject().sceneNode:update()
Expand Down

0 comments on commit a372783

Please sign in to comment.