Skip to content

Commit

Permalink
Refactor projectiles part 1 (FAForever#4528)
Browse files Browse the repository at this point in the history
* pass 1

* mire files

* pass 2

* Pass 3

* Fix File based on review

* More File Chages

Updated based on feedback from second PR

* Add base function to OnEnterWater
  • Loading branch information
MrRowey authored Dec 29, 2022
1 parent a89c5cb commit 461929c
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 183 deletions.
2 changes: 1 addition & 1 deletion lua/aeonprojectiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ADepthChargeProjectile = Class(OnWaterEntryEmitterProjectile) {
FxTrails = {'/effects/emitters/torpedo_munition_trail_01_emit.bp',},
TrailDelay = 0,
TrackTime = 0,

FxImpactLand = {},
FxImpactUnit = EffectTemplate.ADepthChargeHitUnit01,
FxImpactProp = EffectTemplate.ADepthChargeHitUnit01,
Expand Down
14 changes: 13 additions & 1 deletion lua/sim/DefaultProjectiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ OnWaterEntryEmitterProjectile = Class(Projectile) {
PolyTrailOffset = 0,
TrailDelay = 5,
EnterWaterSound = 'Torpedo_Enter_Water_01',
FxEnterWater= {
'/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',
},

---@param self OnWaterEntryEmitterProjectile
---@param inWater boolean
Expand Down Expand Up @@ -433,9 +437,17 @@ OnWaterEntryEmitterProjectile = Class(Projectile) {
---@param self OnWaterEntryEmitterProjectile
OnEnterWater = function(self)
Projectile.OnEnterWater(self)
local army = self.Army
for i in self.FxEnterWater do
CreateEmitterAtEntity(self,army,self.FxEnterWater[i])
end

self:SetVelocityAlign(true)
self:SetStayUpright(false)
self:TrackTarget(true)
self:StayUnderwater(true)
self.TTT1 = self:ForkThread(self.EnterWaterThread)
self:SetVelocity(0.5)
self.Trash:Add(ForkThread(self.EnterWaterThread, self))
end,

---@param self OnWaterEntryEmitterProjectile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-- Cybran Anti Air Quantum Displacement Autocannon Projectile

-- uaa0303
-- Cybran Anti Air Quantum Displacement Autocannon Projectile - UAA0303
local AAAQuantumDisplacementCannonProjectile = import("/lua/aeonprojectiles.lua").AAAQuantumDisplacementCannonProjectile
AAAAutocannonQuantum01 = Class(AAAQuantumDisplacementCannonProjectile) { }
TypeClass = AAAAutocannonQuantum01
TypeClass = AAAAutocannonQuantum01
7 changes: 2 additions & 5 deletions projectiles/AAAFizz01/AAAFizz01_script.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
-- Aeon Anti Air Missile

-- uaa0310, uab2204, ual0205
-- Aeon Anti Air Missile - UAA0310, UAB2204, UAL0205
local ATemporalFizzAAProjectile = import("/lua/aeonprojectiles.lua").ATemporalFizzAAProjectile
AAAFizz01 = Class(ATemporalFizzAAProjectile) { }
TypeClass = AAAFizz01

TypeClass = AAAFizz01
18 changes: 10 additions & 8 deletions projectiles/AANDepthCharge01/AANDepthCharge01_script.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
-- Depth Charge Script

local ADepthChargeProjectile = import("/lua/aeonprojectiles.lua").ADepthChargeProjectile
local VisionMarkerOpti = import("/lua/sim/VizMarker.lua").VisionMarkerOpti

AANDepthCharge01 = Class(ADepthChargeProjectile) {

CountdownLengthInTicks = 100,
FxEnterWater= {
'/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',
},
CountdownLengthInTicks = 101,

OnCreate = function(self)
ADepthChargeProjectile.OnCreate(self)
Expand All @@ -24,14 +18,22 @@ AANDepthCharge01 = Class(ADepthChargeProjectile) {
end
end,

OnEnterWater = function(self)
ADepthChargeProjectile.OnEnterWater(self)
self:SetMaxSpeed(20)
self:SetVelocity(0)
self:SetAcceleration(5)
self:SetTurnRate(180)
end,

OnLostTarget = function(self)
self:SetMaxSpeed(2)
self:SetAcceleration(-0.6)
self.Trash:Add(ForkThread(self.CountdownMovement, self))
end,

CountdownMovement = function(self)
WaitTicks(30)
WaitTicks(31)
self:SetMaxSpeed(0)
self:SetAcceleration(0)
self:SetVelocity(0)
Expand Down
23 changes: 6 additions & 17 deletions projectiles/AANDepthCharge02/AANDepthCharge02_script.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
-- Depth Charge Script

local ADepthChargeProjectile = import("/lua/aeonprojectiles.lua").ADepthChargeProjectile
local VizMarker = import("/lua/sim/vizmarker.lua").VizMarker
local VisionMarkerOpti = import("/lua/sim/vizmarker.lua").VisionMarkerOpti

AANDepthCharge01 = Class(ADepthChargeProjectile) {

FxEnterWater= { '/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',},

OnImpact = function(self, TargetType, TargetEntity)
local pos = self:GetPosition()
local spec = {
X = pos[1],
Z = pos[3],
Radius = 30,
LifeTime = 10,
Omni = false,
Vision = false,
Army = self:GetArmy(),
}
local vizEntity = VizMarker(spec)
local px,_,pz = self:GetPositionXYZ()
local marker = VisionMarkerOpti({Owner = self})
marker:UpdatePostion(px,pz)
marker:UpdateDuration(5)
marker:UpdateIntel(self.Army, 5, 'Vision', true)
ADepthChargeProjectile.OnImpact(self, TargetType, TargetEntity)
end,
}
Expand Down
48 changes: 12 additions & 36 deletions projectiles/AANDepthCharge03/AANDepthCharge03_script.lua
Original file line number Diff line number Diff line change
@@ -1,71 +1,47 @@
-- Depth Charge Script

local ADepthChargeProjectile = import("/lua/aeonprojectiles.lua").ADepthChargeProjectile
local VizMarker = import("/lua/sim/vizmarker.lua").VizMarker
local VisionMarkerOpti = import("/lua/sim/vizmarker.lua").VisionMarkerOpti

AANDepthCharge03 = Class(ADepthChargeProjectile) {

CountdownLength = 10,
FxEnterWater= { '/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',},
CountdownLength = 101,

OnCreate = function(self)
ADepthChargeProjectile.OnCreate(self)
self.HasImpacted = false
self:ForkThread(self.CountdownExplosion)
self.Trash:Add(ForkThread(self.CountdownExplosion,self))
end,

CountdownExplosion = function(self)
WaitSeconds(self.CountdownLength)

WaitTicks(self.CountdownLength)
if not self.HasImpacted then
self:OnImpact('Underwater', nil)
end
end,

OnEnterWater = function(self)
for i in self.FxEnterWater do --splash
CreateEmitterAtEntity(self, self.Army, self.FxEnterWater[i])
end

self:TrackTarget(true)
self:StayUnderwater(true)
ADepthChargeProjectile.OnEnterWater(self)
self:SetTurnRate(360)
self:SetVelocityAlign(true)
self:SetStayUpright(false)
end,

EnterWaterMovementThread = function(self)
WaitTicks(1)
self:SetVelocity(0.5)
end,

OnLostTarget = function(self)
self:SetMaxSpeed(2)
self:SetAcceleration(-0.6)
self:ForkThread(self.CountdownMovement)
self.Trash:Add(ForkThread(self.CountdownMovement,self))
end,

CountdownMovement = function(self)
WaitSeconds(3)
WaitTicks(31)
self:SetMaxSpeed(0)
self:SetAcceleration(0)
self:SetVelocity(0)
end,

OnImpact = function(self, TargetType, TargetEntity)
self.HasImpacted = true
local pos = self:GetPosition()
local spec = {
X = pos[1],
Z = pos[3],
Radius = 30,
LifeTime = 10,
Omni = false,
Vision = false,
Army = self.Army,
}
local vizEntity = VizMarker(spec)
local px,_,pz = self:GetPositionXYZ()
local marker = VisionMarkerOpti({Owner = self})
marker:UpdatePostion(px,pz)
marker:UpdateDuration(5)
marker:UpdateIntel(self.Army, 5, 'Vision', true)
ADepthChargeProjectile.OnImpact(self, TargetType, TargetEntity)
end,
}
Expand Down
14 changes: 2 additions & 12 deletions projectiles/AANTorpedo02/AANTorpedo02_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ local ATorpedoShipProjectile= import("/lua/aeonprojectiles.lua").ATorpedoShipPro
AANTorpedo02 = Class(ATorpedoShipProjectile) {
FxSplashScale = 1,
FxTrailScale = 0.75,
FxEnterWater= { '/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',},

OnEnterWater = function(self)
ATorpedoShipProjectile.OnEnterWater(self)
local army = self:GetArmy()
for k, v in self.FxEnterWater do --splash
CreateEmitterAtEntity(self, army, v):ScaleEmitter(self.FxSplashScale)
end
end,

OnCreate = function(self, inWater)
ATorpedoShipProjectile.OnCreate(self, inWater)
self:SetMaxSpeed(8)
self:ForkThread( self.MotionThread )
self.Trash:Add(ForkThread( self.MotionThread,self))
end,

MotionThread = function(self)
WaitSeconds( 0.3 )
WaitTicks(4)
self:SetTurnRate(80)
self:SetMaxSpeed(3)
self:SetVelocity(3)
Expand Down
34 changes: 7 additions & 27 deletions projectiles/AANTorpedoCluster01/AANTorpedoCluster01_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@
-- Copyright © 2007 Gas Powered Games, Inc. All rights reserved.
---------------------------------------------------------------------------------------
local ATorpedoCluster = import("/lua/aeonprojectiles.lua").ATorpedoCluster
local VizMarker = import("/lua/sim/vizmarker.lua").VizMarker

-- cache specification table
local CachedSpecifications = {
X = 0,
Z = 0,
Radius = 30,
LifeTime = 10,
Omni = false,
Vision = false,
Army = 0,
}
local VisionMarkerOpti = import("/lua/sim/vizmarker.lua").VisionMarkerOpti

-- upvalue scope for performance
local CreateTrail = CreateTrail

AANTorpedoCluster01 = Class(ATorpedoCluster) {

FxTrail = import("/lua/effecttemplates.lua").ATorpedoPolyTrails01,

FxEnterWater= {'/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',
},

OnCreate = function(self)
ATorpedoCluster.OnCreate(self)
CreateTrail(self, -1, self.Army, self.FxTrail)
Expand All @@ -40,17 +24,13 @@ AANTorpedoCluster01 = Class(ATorpedoCluster) {
-- create two child projectiles
for i = 0, 1 do
proj = self:CreateChildProjectile('/projectiles/AANTorpedoClusterSplit01/AANTorpedoClusterSplit01_proj.bp' )
proj:PassDamageData(self.DamageData)
proj.DamageData = self.DamageData
end

local pos = self:GetPosition()
local spec = CachedSpecifications
spec.X = pos[1]
spec.Z = pos[3]
spec.Army = self.Army

local vizEntity = VizMarker(spec)

local px, _,pz = self:GetPositionXYZ()
local marker = VisionMarkerOpti({Owner = self})
marker:UpdatePosition(px,pz)
marker:UpdateDuration(10)
marker:UpdateIntel(self.Army,5,'Vision',true)
self:Destroy()
end,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,38 @@
-- Copyright © 2007 Gas Powered Games, Inc. All rights reserved.
-------------------------------------------------------------------------------------------------
local ATorpedoCluster = import("/lua/aeonprojectiles.lua").ATorpedoCluster
local VizMarker = import("/lua/sim/vizmarker.lua").VizMarker
local VisionMarkerOpti = import("/lua/sim/vizmarker.lua").VisionMarkerOpti

AANTorpedoCluster01 = Class(ATorpedoCluster) {

CountdownLength = 10,
FxEnterWater= { '/effects/emitters/water_splash_ripples_ring_01_emit.bp',
'/effects/emitters/water_splash_plume_01_emit.bp',},
CountdownLength = 101,

OnCreate = function(self)
ATorpedoCluster.OnCreate(self)
self.HasImpacted = false
self:ForkThread(self.CountdownExplosion)
CreateTrail(self, -1, self:GetArmy(), import("/lua/effecttemplates.lua").ATorpedoPolyTrails01)
self.Trash:Add(ForkThread(self.CountdownExplosion,self))
CreateTrail(self, -1, self.Army, import("/lua/effecttemplates.lua").ATorpedoPolyTrails01)

end,

CountdownExplosion = function(self)
WaitSeconds(self.CountdownLength)

WaitTicks(self.CountdownLength)
if not self.HasImpacted then
self:OnImpact('Underwater', nil)
end
end,

OnEnterWater = function(self)
ATorpedoCluster.OnEnterWater(self)
local army = self:GetArmy()
for i in self.FxEnterWater do --splash
local army = self.Army
for i in self.FxEnterWater do
CreateEmitterAtEntity(self,army,self.FxEnterWater[i])
end
self:ForkThread(self.EnterWaterMovementThread)
self.Trash:Add(ForkThread(self.EnterWaterMovementThread,self))
end,

EnterWaterMovementThread = function(self)
self:SetAcceleration(2.5)
self:TrackTarget(true)
self:TrackTarget(true)
self:StayUnderwater(true)
self:SetTurnRate(180)
self:SetStayUpright(false)
Expand All @@ -48,29 +45,22 @@ AANTorpedoCluster01 = Class(ATorpedoCluster) {
OnLostTarget = function(self)
self:SetMaxSpeed(2)
self:SetAcceleration(-0.6)
self:ForkThread(self.CountdownMovement)
self.Trash:Add(ForkThread(self.CountdownMovement,self))
end,

CountdownMovement = function(self)
WaitSeconds(3)
WaitTicks(31)
self:SetMaxSpeed(0)
self:SetAcceleration(0)
self:SetVelocity(0)
end,

OnImpact = function(self, TargetType, TargetEntity)
self.HasImpacted = true
local pos = self:GetPosition()
local spec = {
X = pos[1],
Z = pos[3],
Radius = 30,
LifeTime = 10,
Omni = false,
Vision = false,
Army = self:GetArmy(),
}
local vizEntity = VizMarker(spec)
local px,_,pz = self:GetPositionXYZ()
local marker = VisionMarkerOpti({Owner = self})
marker:UpdatePosition(px,pz)
marker:UpdateDuration(5)
marker:UpdateIntel(self.Army, 5,'Vision',true)
ATorpedoCluster.OnImpact(self, TargetType, TargetEntity)
end,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
local AReactonCannonProjectile = import("/lua/aeonprojectiles.lua").AReactonCannonProjectile
ADFReactonCannon01 = Class(AReactonCannonProjectile) {
CreateImpactEffects = function(self, army, EffectTable, EffectScale)
local launcher = self:GetLauncher()
local launcher = self.Launcher
if launcher and launcher:HasEnhancement('StabilitySuppressant') then
CreateLightParticle(self, -1, self.Army, 3.0, 6, 'ring_05', 'ramp_green_02')
CreateEmitterAtEntity(self, self.Army,'/effects/emitters/oblivion_cannon_hit_11_emit.bp')
Expand Down
Loading

0 comments on commit 461929c

Please sign in to comment.