Skip to content

Commit

Permalink
Code Formatting Units V1 (FAForever#5759)
Browse files Browse the repository at this point in the history
Co-authored-by: lL1l1 <[email protected]>
  • Loading branch information
MrRowey and lL1l1 authored May 30, 2024
1 parent c2da9fc commit b3de37c
Show file tree
Hide file tree
Showing 40 changed files with 675 additions and 390 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/fix.5759.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#5759) Fix rotators on Aeon T2 shield never restarting and on T3 Mass Fabricator never stopping.
3 changes: 3 additions & 0 deletions changelog/snippets/other.5759.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- (#5759) Refactor Seraphim Lightning Tank's weapons and collision beams.

- (#5759) Reduce overhead of many unit scripts.
2 changes: 1 addition & 1 deletion engine/Sim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ end
--- Creates a manipulator which rotates on a unit's bone
---@param object BoneObject
---@param bone Bone
---@param axis "x" | "y" | "z"
---@param axis "x" | "y" | "z" | "-x" | "-y" | "-z"
---@param goal? unknown
---@param speed? number
---@param accel? number
Expand Down
2 changes: 1 addition & 1 deletion engine/Sim/CRotateManipulator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
function CRotateManipulator:SetSpeed(degreesPerSecond)
end

---
--- When `true`, first decelerates to 2% target speed and then stops at 0 degrees. Does not stop if at negative 2% speed
---@param spinDown boolean
function CRotateManipulator:SetSpinDown(spinDown)
end
Expand Down
2 changes: 2 additions & 0 deletions lua/seraphimweapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- Copyright © 2007 Gas Powered Games, Inc. All rights reserved.
-----------------------------------------------------------------------------------------------------------

SAALightningWeapon = import("/lua/sim/weapons/seraphim/SAALightningWeapon.lua").SAALightningWeapon
SANAnaitTorpedo = import('/lua/sim/weapons/seraphim/SANAnaitTorpedo.lua').SANAnaitTorpedo
SDFExperimentalPhasonProj = import('/lua/sim/weapons/seraphim/SDFExperimentalPhasonProj.lua').SDFExperimentalPhasonProj
SDFAireauWeapon = import('/lua/sim/weapons/seraphim/SDFAireauWeapon.lua').SDFAireauWeapon
Expand Down Expand Up @@ -52,6 +53,7 @@ SDFHeavyQuarnonCannon = import('/lua/sim/weapons/seraphim/SDFHeavyQuarnonCannon.
SDFSniperShotNormalMode = import('/lua/sim/weapons/seraphim/SDFSniperShotNormalMode.lua').SDFSniperShotNormalMode
SDFSniperShotSniperMode = import('/lua/sim/weapons/seraphim/SDFSniperShotSniperMode.lua').SDFSniperShotSniperMode
SB0OhwalliExperimentalStrategicBombWeapon = import('/lua/sim/weapons/seraphim/SB0OhwalliExperimentalStrategicBombWeapon.lua').SB0OhwalliExperimentalStrategicBombWeapon
SAALightningWeapon = import("/lua/sim/weapons/seraphim/SAALightningWeapon.lua").SAALightningWeapon

--- Kept Mod Support
local WeaponFile = import("/lua/sim/defaultweapons.lua")
Expand Down
25 changes: 25 additions & 0 deletions lua/sim/collisionBeams/LightningSmallCollisionBeam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local SCCollisionBeam = import("/lua/sim/collisionBeams/SCCollisionBeam.lua").SCCollisionBeam

LightningSmallCollisionBeam = Class(SCCollisionBeam) {
FxBeamStartPoint = {
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_01_emit.bp',
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_02_emit.bp',
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_03_emit.bp',
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_04_emit.bp',
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_05_emit.bp',
'/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_06_emit.bp',
'/Effects/Emitters/seraphim_electricity_emit.bp'
},
FxBeam = {
'/Effects/Emitters/seraphim_lightning_beam_01_emit.bp',
},
FxBeamEndPoint = {
'/Effects/Emitters/seraphim_lightning_hit_01_emit.bp',
'/Effects/Emitters/seraphim_lightning_hit_02_emit.bp',
'/Effects/Emitters/seraphim_lightning_hit_03_emit.bp',
'/Effects/Emitters/seraphim_lightning_hit_04_emit.bp',
},

TerrainImpactType = 'LargeBeam01',
TerrainImpactScale = 0.2,
}
63 changes: 63 additions & 0 deletions lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
local EffectTemplate = import("/lua/effecttemplates.lua")
local Util = import("/lua/utilities.lua")

local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam
local LightningSmallCollisionBeam = import("/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua").LightningSmallCollisionBeam

LightningSmallSurfaceCollisionBeam = Class(LightningSmallCollisionBeam) {
TerrainImpactScale = 0.1,
FxBeam = { '/Effects/Emitters/seraphim_lightning_beam_02_emit.bp', },

SplatTexture = 'czar_mark01_albedo',
ScorchSplatDropTime = 0.25,

---@param self LightningSmallSurfaceCollisionBeam
---@param impactType ImpactType
---@param targetEntity? Prop|Unit
OnImpact = function(self, impactType, targetEntity)
if impactType ~= 'Shield' and impactType ~= 'Water' and impactType ~= 'Air' and impactType ~= 'UnitAir' and impactType ~= 'Projectile' then
if self.Scorching == nil then
self.Scorching = self:ForkThread(self.ScorchThread)
end
else
KillThread(self.Scorching)
self.Scorching = nil
end
CollisionBeam.OnImpact(self, impactType, targetEntity)
end,

---@param self LightningSmallSurfaceCollisionBeam
OnDisable = function(self)
CollisionBeam.OnDisable(self)
KillThread(self.Scorching)
self.Scorching = nil
end,

---@param self LightningSmallSurfaceCollisionBeam
ScorchThread = function(self)
local army = self:GetArmy()
local size = 1.1 + (Random() * 1.1)
local CurrentPosition = self:GetPosition(1)
local LastPosition = Vector(0,0,0)
local skipCount = 1
-- local FriendlyFire = self.DamageData.DamageFriendly

while true do
if Util.GetDistanceBetweenTwoVectors(CurrentPosition, LastPosition) > 0.25 or skipCount > 100 then
CreateSplat( CurrentPosition, Util.GetRandomFloat(0,2*math.pi), self.SplatTexture, size, size, 100, 100, army )
LastPosition = CurrentPosition
skipCount = 1

-- commented due to hard-crash potential
-- DamageArea(self, CurrentPosition, size, 1, 'Force', FriendlyFire)
-- DamageArea(self, CurrentPosition, size, 1, 'Force', FriendlyFire)
else
skipCount = skipCount + self.ScorchSplatDropTime
end

WaitSeconds(self.ScorchSplatDropTime)
size = 1 + (Random() * 1.1)
CurrentPosition = self:GetPosition(1)
end
end,
}
12 changes: 12 additions & 0 deletions lua/sim/weapons/seraphim/SAALightningWeapon.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local DefaultBeamWeapon = import("/lua/sim/defaultweapons.lua").DefaultBeamWeapon
local EffectTemplate = import('/lua/effecttemplates.lua')
local LightningSmallCollisionBeam = import("/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua").LightningSmallCollisionBeam

--- Used by DSLK004
---@class SAALightningWeapon : DefaultProjectileWeapon
SAALightningWeapon = ClassWeapon(DefaultBeamWeapon) {
BeamType = LightningSmallCollisionBeam,
FxMuzzleFlash = { },
FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
FxUpackingChargeEffectScale = 0.2,
}
14 changes: 5 additions & 9 deletions units/DAA0206/DAA0206_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,31 @@
-- Copyright © 2007 Gas Powered Games, Inc. All rights reserved.
------------------------------------------------------------------------------


local AAirUnit = import("/lua/aeonunits.lua").AAirUnit
local DefaultProjectileWeapon = import("/lua/sim/defaultweapons.lua").DefaultProjectileWeapon
local VisionMarker = import("/lua/sim/vizmarker.lua").VisionMarkerOpti

---@class DAA0206 : AAirUnit
DAA0206 = ClassUnit(AAirUnit) {
--ContrailEffects = {
-- '/effects/emitters/contrail_ser_ohw_polytrail_01_emit.bp',
--},

Weapons = {
Suicide = ClassWeapon(DefaultProjectileWeapon) {}
},

---@param self DAA0206
OnRunOutOfFuel = function(self)
self:Kill()
end,

---@param self DAA0206
ProjectileFired = function(self)
self:GetWeapon(1).IdleState.Main = function(self) end
self:PlayUnitSound('Killed')
self:PlayUnitSound('Destroyed')

self:PlayUnitSound('Destroyed')
self:Destroy()
end,
}
TypeClass = DAA0206

-- Kept for Mod Backwards Compatablity
local EffectTemplate = import('/lua/effecttemplates.lua')
local EffectUtils = import('/lua/effectutilities.lua')
local EffectUtils = import('/lua/effectutilities.lua')
local VisionMarker = import("/lua/sim/vizmarker.lua").VisionMarkerOpti
4 changes: 3 additions & 1 deletion units/DAL0310/DAL0310_Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ DAL0310 = ClassUnit(AHoverLandUnit) {
Weapons = {
MainGun = ClassWeapon(ADFDisruptorCannonWeapon) {
CreateProjectileAtMuzzle = function(self, muzzle)
local bp = self.Blueprint

local proj = ADFDisruptorCannonWeapon.CreateProjectileAtMuzzle(self, muzzle)
local data = self:GetBlueprint().DamageToShields
local data = bp.DamageToShields
if proj and not proj:BeenDestroyed() then
proj:PassData(data)
end
Expand Down
54 changes: 35 additions & 19 deletions units/DEA0202/DEA0202_Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ local TAirUnit = import("/lua/terranunits.lua").TAirUnit
local TAirToAirLinkedRailgun = import("/lua/terranweapons.lua").TAirToAirLinkedRailgun
local TIFCarpetBombWeapon = import("/lua/terranweapons.lua").TIFCarpetBombWeapon

-- upvalue for perfomance
local TrashBagAdd = TrashBag.Add

---@class DEA0202 : TAirUnit
DEA0202 = ClassUnit(TAirUnit) {
Weapons = {
Expand All @@ -20,60 +23,72 @@ DEA0202 = ClassUnit(TAirUnit) {
Bomb = ClassWeapon(TIFCarpetBombWeapon) {

IdleState = State(TIFCarpetBombWeapon.IdleState) {

---@param self DEA0202
Main = function(self)
TIFCarpetBombWeapon.IdleState.Main(self)
end,

---@param self DEA0202
OnGotTarget = function(self)
if self.unit:IsUnitState('Moving') then
self.unit:SetSpeedMult(1.0)
local unit = self.unit

if unit:IsUnitState('Moving') then
unit:SetSpeedMult(1.0)
else
self.unit:SetBreakOffTriggerMult(2.0)
self.unit:SetBreakOffDistanceMult(8.0)
self.unit:SetSpeedMult(0.67)
unit:SetBreakOffTriggerMult(2.0)
unit:SetBreakOffDistanceMult(8.0)
unit:SetSpeedMult(0.67)
TIFCarpetBombWeapon.IdleState.OnGotTarget(self)
end
end,

---@param self DEA0202
OnFire = function(self)
self.unit:RotateWings(self:GetCurrentTarget())
local unit = self.unit
unit:RotateWings(self:GetCurrentTarget())
TIFCarpetBombWeapon.IdleState.OnFire(self)
end,
},

OnFire = function(self)
self.unit:RotateWings(self:GetCurrentTarget())
local unit = self.unit
unit:RotateWings(self:GetCurrentTarget())
TIFCarpetBombWeapon.OnFire(self)
end,

OnGotTarget = function(self)
if self.unit:IsUnitState('Moving') then
self.unit:SetSpeedMult(1.0)
local unit = self.unit
if unit:IsUnitState('Moving') then
unit:SetSpeedMult(1.0)
else
self.unit:SetBreakOffTriggerMult(2.0)
self.unit:SetBreakOffDistanceMult(8.0)
self.unit:SetSpeedMult(0.67)
unit:SetBreakOffTriggerMult(2.0)
unit:SetBreakOffDistanceMult(8.0)
unit:SetSpeedMult(0.67)
TIFCarpetBombWeapon.OnGotTarget(self)
end
end,

OnLostTarget = function(self)
self.unit:SetBreakOffTriggerMult(1.0)
self.unit:SetBreakOffDistanceMult(1.0)
self.unit:SetSpeedMult(1.0)
local unit = self.unit
unit:SetBreakOffTriggerMult(1.0)
unit:SetBreakOffDistanceMult(1.0)
unit:SetSpeedMult(1.0)
TIFCarpetBombWeapon.OnLostTarget(self)
end,
},
},


RotateWings = function(self, target)
local trash = self.Trash

if not self.LWingRotator then
self.LWingRotator = CreateRotator(self, 'Left_Wing', 'y')
self.Trash:Add(self.LWingRotator)
TrashBagAdd(trash, self.LWingRotator)
end
if not self.RWingRotator then
self.RWingRotator = CreateRotator(self, 'Right_Wing', 'y')
self.Trash:Add(self.RWingRotator)
TrashBagAdd(trash, self.RWingRotator)
end
local fighterAngle = -105
local bomberAngle = 0
Expand Down Expand Up @@ -101,7 +116,8 @@ DEA0202 = ClassUnit(TAirUnit) {

OnCreate = function(self)
TAirUnit.OnCreate(self)
self:ForkThread(self.MonitorWings)
local trash = self.Trash
TrashBagAdd(trash, ForkThread(self.MonitorWings, self))
end,

MonitorWings = function(self)
Expand Down
28 changes: 20 additions & 8 deletions units/DELK002/DELK002_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,45 @@ local TAAPhalanxWeapon = import("/lua/kirvesweapons.lua").TAAPhalanxWeapon
local EffectUtils = import("/lua/effectutilities.lua")
local Effects = import("/lua/effecttemplates.lua")

-- upvalue for performance
local CreateRotator = CreateRotator
local TrashBagAdd = TrashBag.Add

---@class DELK002 : TLandUnit
DELK002 = ClassUnit(TLandUnit) {
Weapons = {
GatlingCannon = ClassWeapon(TAAPhalanxWeapon)
{
PlayFxWeaponPackSequence = function(self)
local unit = self.unit
local army = self.Army

if self.SpinManip1 then
self.SpinManip1:SetTargetSpeed(0)
end
if self.SpinManip2 then
self.SpinManip2:SetTargetSpeed(0)
end
EffectUtils.CreateBoneEffectsOpti(self.unit, 'Left_Muzzle', self.unit.Army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(self.unit, 'Right_Muzzle', self.unit.Army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(unit, 'Left_Muzzle', army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(unit, 'Right_Muzzle', army, Effects.WeaponSteam01)
TAAPhalanxWeapon.PlayFxWeaponPackSequence(self)
end,

PlayFxRackSalvoChargeSequence = function(self)
local trash = self.Trash
local unit = self.unit

if not self.SpinManip1 then
self.SpinManip1 = CreateRotator(self.unit, 'Right_Barrel', 'z', nil, 360, 180, 60)
self.unit.Trash:Add(self.SpinManip1)
self.SpinManip1 = CreateRotator(unit, 'Right_Barrel', 'z', nil, 360, 180, 60)
TrashBagAdd(trash, self.SpinManip1)
end

if self.SpinManip1 then
self.SpinManip1:SetTargetSpeed(500)
end
if not self.SpinManip2 then
self.SpinManip2 = CreateRotator(self.unit, 'Left_Barrel', 'z', nil, 360, 180, 60)
self.unit.Trash:Add(self.SpinManip2)
self.SpinManip2 = CreateRotator(unit, 'Left_Barrel', 'z', nil, 360, 180, 60)
TrashBagAdd(trash, self.SpinManip2)
end

if self.SpinManip2 then
Expand All @@ -49,14 +58,17 @@ DELK002 = ClassUnit(TLandUnit) {
end,

PlayFxRackSalvoReloadSequence = function(self)
local unit = self.unit
local army = self.Army

if self.SpinManip1 then
self.SpinManip1:SetTargetSpeed(200)
end
if self.SpinManip2 then
self.SpinManip2:SetTargetSpeed(200)
end
EffectUtils.CreateBoneEffectsOpti(self.unit, 'Left_Muzzle', self.unit.Army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(self.unit, 'Right_Muzzle', self.unit.Army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(unit, 'Left_Muzzle', army, Effects.WeaponSteam01)
EffectUtils.CreateBoneEffectsOpti(unit, 'Right_Muzzle', army, Effects.WeaponSteam01)
TAAPhalanxWeapon.PlayFxRackSalvoChargeSequence(self)
end,
},
Expand Down
Loading

0 comments on commit b3de37c

Please sign in to comment.