Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire Beetle Target Acquisition and Chase Behavior #5558

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
119 changes: 55 additions & 64 deletions units/XRL0302/XRL0302_Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ local CWalkingLandUnit = import("/lua/cybranunits.lua").CWalkingLandUnit
local EffectTemplate = import("/lua/effecttemplates.lua")
local Weapon = import("/lua/sim/weapon.lua").Weapon

local DeathWeaponKamikaze = ClassWeapon(Weapon) {
OnFire = function(self)
if not self.unit.Dead then
self.unit:Kill()
end
end,
}

local DeathWeaponEMP = ClassWeapon(Weapon) {

FxDeath = EffectTemplate.CMobileKamikazeBombExplosion,
OnCreate = function(self)
Weapon.OnCreate(self)
self:SetWeaponEnabled(false)
end,

Fire = function(self)
OnFire = function(self)
Weapon.OnFire(self)

-- Disable our death weapon so we don't fire it again
self.unit:SetDeathWeaponEnabled(false)

local blueprint = self.Blueprint
local position = self.unit:GetPosition()

Expand All @@ -32,18 +26,54 @@ local DeathWeaponEMP = ClassWeapon(Weapon) {
CreateEmitterAtBone(self.unit, -2, army, v)
end

-- Do tree knockdown if we're not in a transport
if not self.unit.transportDrop then
local rotation = math.random(0, 6.28)
DamageArea(self.unit, position, 6, 1, 'TreeForce', true)
DamageArea(self.unit, position, 6, 1, 'TreeForce', true)
DamageArea(self.unit, position, blueprint.DamageRadius, 1, 'TreeForce', true)
CreateDecal(position, rotation, 'scorch_010_albedo', '', 'Albedo', 11, 11, 250, 120, army)
end

-- Do damage
DamageArea(self.unit, position, blueprint.DamageRadius, blueprint.Damage, blueprint.DamageType or 'Normal',
blueprint.DamageFriendly or false)
self.unit:PlayUnitSound('Destroyed')

-- Kill unit if it's not already dead
if not self.unit.Dead then
self.unit:Kill()
end

-- Don't leave wreckage
self.unit:Destroy()
end,

-- This prevents us from firing the death weapon when we're moving
-- also gives much better tailchase performance by adjusting the detonation range
OnMotionHorzEventChange = function(self, new, old)
if new == 'Cruise' then
self:SetEnabled(false)
elseif new == 'Stopping' then
if not self.unit:IsUnitState('Moving') then
self:SetEnabled(true)
if self.unit:IsUnitState('Attacking') then
local target = self.unit:GetCommandQueue()[1].target
if target then
local dist = VDist3(self.unit:GetPosition(), target:GetPosition())
if not self.chasing and dist < self.Blueprint.MaxRadius or
self.chasing and dist < self.Blueprint.DamageRadius then
self:FireWeapon()
end
end
self.unit:GetNavigator():SetSpeedThroughGoal(true)
self.chasing = true
end
end
elseif new == 'Stopped' then
self:SetEnabled(true)
self.unit:GetNavigator():SetSpeedThroughGoal(false)
self.chasing = nil
end
end,
}

---@class XRL0302 : CWalkingLandUnit
Expand All @@ -65,78 +95,39 @@ XRL0302 = ClassUnit(CWalkingLandUnit) {
},

Weapons = {
Suicide = ClassWeapon(DeathWeaponKamikaze) {},
DeathWeapon = ClassWeapon(DeathWeaponEMP) {},
},

AmbientExhaustBones = {
'XRL0302',
},

AmbientLandExhaustEffects = {
'/effects/emitters/cannon_muzzle_smoke_12_emit.bp',
KamikazeEMP = ClassWeapon(DeathWeaponEMP) {},
},

OnCreate = function(self)
CWalkingLandUnit.OnCreate(self)
self.EffectsBagXRL = TrashBag()
self.AmbientExhaustEffectsBagXRL = TrashBag()
self:CreateTerrainTypeEffects(self.IntelEffects.Cloak, 'FXIdle', self.Layer, nil, self.EffectsBag)
self.PeriodicFXThread = ForkThread(self.EmitPeriodicEffects, self)
self.Trash:Add(self.PeriodicFXThread)
self:CreateTerrainTypeEffects(self.IntelEffects.Cloak, 'FXIdle', self.Layer, nil, self.Trash)
end,

OnStopBeingBuilt = function(self, builder, layer)
CWalkingLandUnit.OnStopBeingBuilt(self, builder, layer)
self.Trash:Add(ForkThread(self.HideUnit, self))

-- Enable our death weapon
self:SetDeathWeaponEnabled(true)
end,

HideUnit = function(self)
WaitTicks(1)
self:SetMesh(self.Blueprint.Display.CloakMeshBlueprint, true)
end,

OnProductionPaused = function(self)
self:GetWeaponByLabel('Suicide'):FireWeapon()
end,

EmitPeriodicEffects = function(self)
local army = self.Army
local ambientLandExhaustEffects = self.AmbientLandExhaustEffects
local ambientExhaustBones = self.AmbientExhaustBones

while not self.Dead do
for kE, vE in ambientLandExhaustEffects do
for kB, vB in ambientExhaustBones do
CreateAttachedEmitter(self, vB, army, vE)
end
end
WaitTicks(31)
end
-- Use the special toggle instead of production pausing as our detonator
EnableSpecialToggle = function(self)
self:GetWeaponByLabel('KamikazeEMP'):FireWeapon()
end,

DoDeathWeapon = function(self)
if self:IsBeingBuilt() then return end
CWalkingLandUnit.DoDeathWeapon(self)
self.EffectsBagXRL:Destroy()
self.AmbientExhaustEffectsBagXRL:Destroy()
self.PeriodicFXThread:Destroy()
self.PeriodicFXThread = nil
local bp
for k, v in self.Blueprint.Buffs do
if v.Add.OnDeath then
bp = v
end
end

if bp ~= nil then
self:AddBuff(bp)
end
self:GetWeaponByLabel('KamikazeEMP'):FireWeapon()
end,
}

TypeClass = XRL0302

-- Kept for mod support
local CMobileKamikazeBombWeapon = import("/lua/cybranweapons.lua").CMobileKamikazeBombWeapon
local EffectUtil = import("/lua/effectutilities.lua")
local EffectUtil = import("/lua/effectutilities.lua")
102 changes: 23 additions & 79 deletions units/XRL0302/XRL0302_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ UnitBlueprint{
StopMove = Sound { Bank = 'XRL', Cue = 'XRL0302_Move_Stop', LodCutoff = 'UnitMove_LodCutoff' },
UISelection = Sound { Bank = 'Interface', Cue = 'Cybran_Select_Vehicle', LodCutoff = 'UnitMove_LodCutoff' },
},
Buffs = {
Stun = {
Add = {
OnDeath = true,
OnImpact = true,
},
AppliedToTarget = false,
BuffType = "STUN",
Duration = 2,
Radius = 7,
TargetAllow = "MOBILE",
TargetDisallow = "EXPERIMENTAL, WALL, COMMAND",
},
},
BuildIconSortPriority = 80,
Categories = {
"BOMB",
Expand Down Expand Up @@ -93,7 +79,7 @@ UnitBlueprint{
Economy = {
BuildCostEnergy = 1300,
BuildCostMass = 190,
BuildTime = 700,
BuildTime = 550,
TeleportEnergyMod = 0.15,
TeleportMassMod = 1,
TeleportTimeMod = 0.01,
Expand All @@ -117,12 +103,12 @@ UnitBlueprint{
Icon = "land",
InstantDeathOnSelfDestruct = true,
OrderOverrides = {
RULEUTC_ProductionToggle = {
RULEUTC_SpecialToggle = {
bitmapId = "overcharge",
helpText = "Detonate",
},
},
ToggleCaps = { RULEUTC_ProductionToggle = true },
ToggleCaps = { RULEUTC_SpecialToggle = true },
UnitName = "<LOC xrl0302_name>Fire Beetle",
},
Intel = {
Expand Down Expand Up @@ -173,84 +159,42 @@ UnitBlueprint{
Weapon = {
{
AboveWaterTargetsOnly = true,
AlwaysRecheckTarget = false,
AutoInitiateAttackCommand = true,
Buffs = {
{
Add = { OnFire = true },
BuffType = "STUN",
Duration = 2,
Radius = 7,
TargetAllow = "MOBILE",
TargetDisallow = "EXPERIMENTAL, WALL, COMMAND",
},
},
CollideFriendly = false,
Damage = 1,
Damage = 1100,
DamageFriendly = false,
DamageRadius = 6.5,
DamageType = "FireBeetleExplosion",
DisplayName = "Suicide",
DisplayName = "Kamikaze",
FireTargetLayerCapsTable = {
Land = "Land|Water|Seabed",
Water = "Land|Water|Seabed",
},
FiringTolerance = 180,
Label = "Suicide",
MaxRadius = 3,
TargetPriorities = {
"MOBILE",
"(STRUCTURE * DEFENSE - ANTIMISSILE)",
"ALLUNITS",
},
Label = "KamikazeEMP",
MaxRadius = 2,
RangeCategory = "UWRC_DirectFire",
TargetPriorities = { "ALLUNITS", },
TargetRestrictDisallow = "UNTARGETABLE",
TrackingRadius = 3.25,
Turreted = false,
WeaponCategory = "Kamikaze",
},
{
AboveWaterTargetsOnly = true,
BallisticArc = "RULEUBA_None",
CollideFriendly = false,
Damage = 1100,
DamageFriendly = false,
DamageRadius = 6.5,
DamageType = "EMP",
DisplayName = "EMP",
FireOnDeath = true,
FireTargetLayerCapsTable = {
Air = "Air|Land|Seabed|Water",
Land = "Air|Land|Seabed|Water",
Water = "Air|Land|Water",
},
FiringTolerance = 2,
IgnoreIfDisabled = true,
Label = "DeathWeapon",
MaxRadius = 3,
MuzzleVelocity = 0,
ProjectileId = "/projectiles/CIFEMP01/CIFEMP01_proj.bp",
ProjectileLifetimeUsesMultiplier = 1.15,
RackBones = {
{
MuzzleBones = { 0 },
RackBone = 0,
},
},
RangeCategory = "UWRC_DirectFire",
RateOfFire = 0.5,
SalvoSize = 1,
SlavedToBody = true,
TargetRestrictDisallow = "UNTARGETABLE, AIR",
WeaponCategory = "Direct Fire",
},
{
Damage = 0,
DisplayName = "Detonation Trigger",
FireTargetLayerCapsTable = {
Air = "Land|Water|Seabed",
Land = "Land|Water|Seabed",
},
Label = "ExplosionRadiusRingDummyWeapon",
MaxRadius = 6.5,
MuzzleSalvoDelay = 1,
MuzzleSalvoSize = 0,
ProjectileId = "/projectiles/CDFRocketMeson01/CDFRocketMeson01_proj.bp",
RackBones = {
{
MuzzleBones = { 0 },
RackBone = 0,
},
},
RackRecoilDistance = 0,
RangeCategory = "UWRC_IndirectFire",
TargetRestrictDisallow = "UNTARGETABLE AIR",
RangeCategory = "UWRC_DirectFire",
},
},
Wreckage = {
Expand Down