Skip to content

Commit

Permalink
OLOB firepit compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaakma committed Dec 2, 2024
1 parent 78e2e62 commit f37825f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local CampfireUtil = require("mer.ashfall.camping.campfire.CampfireUtil")
local HeatUtil = require("mer.ashfall.heat.HeatUtil")
local foodConfig = common.staticConfigs.foodConfig
local campfireConfig = common.staticConfigs.campfireConfig
local CraftingFramework = require("CraftingFramework")
local randomStuffChances = {
utensil = 0.4,
water = 0.6,
Expand All @@ -12,6 +13,12 @@ local randomStuffChances = {
}
local SCALE_MAX = 1.3


local meshOffsets = {
["furn_de_firepit_f.nif"] = -68,
["furn_de_firepit_f_01.nif"] = -68
}

local vanillaCampfires = {
mr_light_pitfire = { replacement = "ashfall_campfire", supports = true, rootHeight = 5, squareSupports = true, infinite = true},
--Ugly ones
Expand Down Expand Up @@ -480,9 +487,11 @@ local function moveFood(campfire, foodList)
end
end
end

end




local function replaceCampfire(e)
local vanillaConfig = vanillaCampfires[e.reference.object.id:lower()]
local campfireReplaced = e.reference.data and e.reference.data.campfireReplaced
Expand Down Expand Up @@ -557,15 +566,16 @@ local function replaceCampfire(e)

table.insert(data.ignoreList, campfire)
local rootHeight = 0 -- vanillaConfig.rootHeight * campfire.scale

local orientedCorrectly = common.helper.orientRefToGround{
ref = campfire,
maxSteepness = (data.hasPlatform and 0.0 or 0.2),
ignoreList = data.ignoreList,
rootHeight = rootHeight+5,
ignoreNonStatics = true,
ignoreBB = true,
--skipPosition = true
maxZ = 10
rootHeight = meshOffsets[e.reference.object.mesh:lower()] or -rootHeight,
maxZ = 10,
recreateBoundingBox = true
}
if not orientedCorrectly then
common.helper.removeCollision(e.reference.sceneNode)
Expand Down
44 changes: 35 additions & 9 deletions Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,16 @@ function this.rotationDifference(vec1, vec2)
return m:toEulerXYZ()
end


---@class Ashfall.getGroundBelowRef.params
---@field ref tes3reference
---@field ignoreList tes3reference[]
---@field rootHeight number
---@field terrainOnly boolean
---@field maxDistance? number
---@field doLog? boolean
---@field recreateBoundingBox boolean This will remove lights/collision from the sceneNode, only use if the ref can be discarded

---@param e Ashfall.getGroundBelowRef.params
---@return niPickRecord|nil
function this.getGroundBelowRef(e)
e.doLog = e.doLog or false
Expand All @@ -635,20 +644,28 @@ function this.getGroundBelowRef(e)
if not ref then
return
end
if not ref.object.boundingBox then
local boundingBox = ref.object.boundingBox
if e.recreateBoundingBox then
this.removeCollision(ref.sceneNode)
this.removeLight(ref.sceneNode)
ref.sceneNode:update()
boundingBox = ref.sceneNode:createBoundingBox()
end
if not boundingBox then
return
end
local height = -ref.object.boundingBox.min.z + (e.rootHeight or 5)
local height = (boundingBox.max.z - boundingBox.min.z)
local pos = ref.position:copy()
pos.z = pos.z + height
pos.z = pos.z + (e.rootHeight or (boundingBox.max.z - (height/2))) * ref.scale
local result = tes3.rayTest{
position = pos,
direction = tes3vector3.new(0, 0, -1),
ignore = ignoreList or {ref, tes3.player},
returnNormal = true,
useBackTriangles = false,
root = e.terrainOnly and tes3.game.worldLandscapeRoot or nil,
maxDistance = e.maxDistance or 500
maxDistance = e.maxDistance or 500,
accurateSkinned = true,
}
if result then
this.logger:trace("Found ground below %s at %s", ref, result.intersection)
Expand Down Expand Up @@ -691,8 +708,17 @@ function this.compareReferenceSize(ref1, ref2)
end
end

---@class Ashfall.orientRefToGround.params
---@field ref tes3reference
---@field maxSteepness? number
---@field ignoreList? tes3reference[]
---@field rootHeight? number
---@field terrainOnly? boolean
---@field ignoreNonStatics? boolean
---@field maxDistance? number
---@field recreateBoundingBox? boolean


---@param params Ashfall.orientRefToGround.params
function this.orientRefToGround(params)
local function orientRef(ref, rayResult, maxSteepness)
local UP = tes3vector3.new(0, 0, 1)
Expand All @@ -714,7 +740,6 @@ function this.orientRefToGround(params)
local ref = params.ref
local maxSteepness = params.maxSteepness or 0.4
local ignoreList = params.ignoreList or {ref, tes3.player}
local rootHeight = params.rootHeight or 0
local terrainOnly = params.terrainOnly or false --only look at terrain
local ignoreNonStatics = params.ignoreNonStatics or false

Expand All @@ -729,9 +754,10 @@ function this.orientRefToGround(params)
local result = this.getGroundBelowRef{
ref = ref,
ignoreList = ignoreList,
rootHeight = rootHeight,
rootHeight = params.rootHeight,
terrainOnly = terrainOnly,
maxDistance = params.maxDistance
maxDistance = params.maxDistance,
recreateBoundingBox = params.recreateBoundingBox
}
if not result then return false end
if not params.skipOrient then
Expand Down

0 comments on commit f37825f

Please sign in to comment.