Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lua/sim/units/AirUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AirUnit = ClassUnit(MobileUnit) {
MobileUnitOnCreate(self)
self.HasFuel = true
self:AddPingPong()
self:RandomiseElevation()
end,

---@param self AirUnit
Expand All @@ -40,6 +41,27 @@ AirUnit = ClassUnit(MobileUnit) {
end
end,

--@param self AirUnit
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to start with 3 --- to be a valid annotation

RandomiseElevation = function(self)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be Randomize with z. The code is originally and mostly written in american english

local maxElevationDelta = 5
Comment thread
cx-koraka marked this conversation as resolved.
Outdated
local maxElevationPercentageIncrease = 5
local maxElevationPercentageDecrease = 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2 different values for increase and decrease when they are the same?
Its not like a mod could easily adjust this, since its hardcoded in this function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I moved these outside of the function, similar to the existing destruction params, would they be able to be changed by mods?
The original version of this had 30 and 0 as the max percentage increase and decrease respectively, this is a holdover

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if they are saved on the class, mods can easily adjust them without touching the function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Hopefully this will make it easier to experiment whilst testing as well


local blueprintPhysics = self.Blueprint.Physics
local originalElevation = blueprintPhysics.Elevation
local elevationMultiplier = math.random(100-maxElevationPercentageDecrease, 100+maxElevationPercentageIncrease) * 0.01
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

local newElevation

if elevationMultiplier > 1 then
newElevation = math.min(originalElevation * elevationMultiplier, originalElevation + 5)
else
newElevation = math.max(originalElevation * elevationMultiplier, originalElevation - 5)
end

self:SetElevation(newElevation)
end,

---@param self AirUnit
---@param new VerticalMovementState
---@param old VerticalMovementState
Expand Down