Public feed
#602689
#****************************************************************************
#**
#** File : /cdimage/lua/modules/terranunits.lua
#** Author(s): John Comes, Dave Tomandl, Gordon Duclos
#**
#** Summary :
#**
#** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
#****************************************************************************
#--------------------------------------------------------------------------
# TERRAN DEFAULT UNITS
#--------------------------------------------------------------------------
local Entity = import('entity.lua').Entity
local util = import('utilities.lua')
local DefaultUnitsFile = import('defaultunits.lua')
local AirFactoryUnit = DefaultUnitsFile.AirFactoryUnit
local AirStagingPlatformUnit = DefaultUnitsFile.AirStagingPlatformUnit
local AirUnit = DefaultUnitsFile.AirUnit
local ConcreteStructureUnit = DefaultUnitsFile.ConcreteStructureUnit
local ConstructionUnit = DefaultUnitsFile.ConstructionUnit
local EnergyCreationUnit = DefaultUnitsFile.EnergyCreationUnit
local EnergyStorageUnit = DefaultUnitsFile.EnergyStorageUnit
local LandFactoryUnit = DefaultUnitsFile.LandFactoryUnit
local LandUnit = DefaultUnitsFile.LandUnit
local MassCollectionUnit = DefaultUnitsFile.MassCollectionUnit
local MassFabricationUnit = DefaultUnitsFile.MassFabricationUnit
local MassStorageUnit = DefaultUnitsFile.MassStorageUnit
local RadarUnit = DefaultUnitsFile.RadarUnit
local SeaFactoryUnit = DefaultUnitsFile.SeaFactoryUnit
local SeaUnit = DefaultUnitsFile.SeaUnit
local ShieldLandUnit = DefaultUnitsFile.ShieldLandUnit
local ShieldStructureUnit = DefaultUnitsFile.ShieldStructureUnit
local SonarUnit = DefaultUnitsFile.SonarUnit
local StructureUnit = DefaultUnitsFile.StructureUnit
local SubUnit = DefaultUnitsFile.SubUnit
local WalkingLandUnit = DefaultUnitsFile.WalkingLandUnit
local WallStructureUnit = DefaultUnitsFile.WallStructureUnit
local QuantumGateUnit = DefaultUnitsFile.QuantumGateUnit
local RadarJammerUnit = DefaultUnitsFile.RadarJammerUnit
local EffectUtil = import('EffectUtilities.lua')
local PlayEffectsAtBones = EffectUtil.CreateBoneTableRangedScaleEffects
local CreateBuildCubeThread = EffectUtil.CreateBuildCubeThread
local CreateUEFBuildSliceBeams = EffectUtil.CreateUEFBuildSliceBeams
#-------------------------------------------------------------
# AIR FACTORY STRUCTURES
#-------------------------------------------------------------
TAirFactoryUnit = Class(AirFactoryUnit) {
CreateBuildEffects = function( self, unitBeingBuilt, order )
WaitSeconds( 0.1 )
for k, v in self.BuildBones.BuildEffectBones do
self.BuildEffectsBag:Add( CreateAttachedEmitter( self, v, self:GetArmy(), '/effects/emitters/flashing_blue_glow_01_emit.bp' ) )
self.BuildEffectsBag:Add( self:ForkThread( EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag ) )
end
end,
OnPaused = function(self)
AirFactoryUnit.OnPaused(self)
self:StopArmsMoving()
end,
OnUnpaused = function(self)
AirFactoryUnit.OnUnpaused(self)
if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
self:StartArmsMoving()
end
end,
OnStartBuild = function(self, unitBeingBuilt, order )
AirFactoryUnit.OnStartBuild(self, unitBeingBuilt, order )
if order != 'Upgrade' then
self:StartArmsMoving()
end
end,
OnStopBuild = function(self, unitBuilding)
AirFactoryUnit.OnStopBuild(self, unitBuilding)
self:StopArmsMoving()
end,
OnFailedToBuild = function(self)
AirFactoryUnit.OnFailedToBuild(self)
self:StopArmsMoving()
end,
StartArmsMoving = function(self)
self.ArmsThread = self:ForkThread(self.MovingArmsThread)
end,
MovingArmsThread = function(self)
end,
StopArmsMoving = function(self)
if self.ArmsThread then
KillThread(self.ArmsThread)
self.ArmsThread = nil
end
end,
}
#-------------------------------------------------------------
# AIR STAGING STRUCTURES
#-------------------------------------------------------------
TAirStagingPlatformUnit = Class(AirStagingPlatformUnit) {
}
#-------------------------------------------------------------
# AIR UNITS
#-------------------------------------------------------------
TAirUnit = Class(AirUnit) {}
#-------------------------------------------------------------
# WALL STRUCTURES
#-------------------------------------------------------------
TConcreteStructureUnit = Class(ConcreteStructureUnit) {
}
#-------------------------------------------------------------
# Construction Units
#-------------------------------------------------------------
TConstructionUnit = Class(ConstructionUnit) {
CreateBuildEffects = function( self, unitBeingBuilt, order )
local UpgradesFrom = unitBeingBuilt:GetBlueprint().General.UpgradesFrom
# If we are assisting an upgrading unit, or repairing a unit, play seperate effects
if (order == 'Repair' and not unitBeingBuilt:IsBeingBuilt()) or (UpgradesFrom and UpgradesFrom != 'none' and self:IsUnitState('Guarding'))then
EffectUtil.CreateDefaultBuildBeams( self, unitBeingBuilt, self.BuildBones.BuildEffectBones, self.BuildEffectsBag )
else
CreateUEFBuildSliceBeams( self, unitBeingBuilt, self.BuildBones.BuildEffectBones, self.BuildEffectsBag )
end
end,
OnLayerChange = function(self, new, old)
ConstructionUnit.OnLayerChange(self, new, old)
if self:GetBlueprint().Display.AnimationWater then
if self.TerrainLayerTransitionThread then
self.TerrainLayerTransitionThread:Destroy()
self.TerrainLayerTransitionThread = nil
end
if (new == 'Land') and (old != 'None') then
self.TerrainLayerTransitionThread = self:ForkThread(self.TransformThread, false)
elseif (new == 'Water') then
self.TerrainLayerTransitionThread = self:ForkThread(self.TransformThread, true)
end
end
end,
TransformThread = function(self, water)
if not self.TransformManipulator then
self.TransformManipulator = CreateAnimator(self)
self.Trash:Add( self.TransformManipulator )
end
if water then
self.TransformManipulator:PlayAnim(self:GetBlueprint().Display.AnimationWater)
self.TransformManipulator:SetRate(1)
self.TransformManipulator:SetPrecedence(0)
else
self.TransformManipulator:SetRate(-1)
self.TransformManipulator:SetPrecedence(0)
WaitFor(self.TransformManipulator)
self.TransformManipulator:Destroy()
self.TransformManipulator = nil
end
end,
}
#-------------------------------------------------------------
# ENERGY CREATION STRUCTURES
#-------------------------------------------------------------
TEnergyCreationUnit = Class(EnergyCreationUnit) {
}
#-------------------------------------------------------------
# ENERGY STORAGE STRUCTURES
#-------------------------------------------------------------
TEnergyStorageUnit = Class(EnergyStorageUnit) {
}
#-------------------------------------------------------------
# HOVER LAND UNITS
#-------------------------------------------------------------
THoverLandUnit = Class(DefaultUnitsFile.HoverLandUnit) {
}
#-------------------------------------------------------------
# LAND FACTORY STRUCTURES
#-------------------------------------------------------------
TLandFactoryUnit = Class(LandFactoryUnit) {
CreateBuildEffects = function( self, unitBeingBuilt, order )
WaitSeconds( 0.1 )
for k, v in self.BuildBones.BuildEffectBones do
self.BuildEffectsBag:Add( CreateAttachedEmitter( self, v, self:GetArmy(), '/effects/emitters/flashing_blue_glow_01_emit.bp' ) )
self.BuildEffectsBag:Add( self:ForkThread( EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag ) )
end
end,
}
#-------------------------------------------------------------
# LAND UNITS
#-------------------------------------------------------------
TLandUnit = Class(LandUnit) {
}
#-------------------------------------------------------------
# MASS COLLECTION UNITS
#-------------------------------------------------------------
TMassCollectionUnit = Class(MassCollectionUnit) {
### FIXME ### Until these units get an upgrade animation, these will be visible during upgrade
# This causes them both to be shown while it upgrades, this over-riden function can be removed
# once it is.
StartBeingBuiltEffects = function(self, builder, layer)
self:SetMesh(self:GetBlueprint().Display.BuildMeshBlueprint, true)
if self:GetBlueprint().General.UpgradesFrom != builder:GetUnitId() then
self:HideBone(0, true)
self.OnBeingBuiltEffectsBag:Add( self:ForkThread( CreateBuildCubeThread, builder, self.OnBeingBuiltEffectsBag ))
end
end,
}
#-------------------------------------------------------------
# MASS FABRICATION STRUCTURES
#-------------------------------------------------------------
TMassFabricationUnit = Class(MassFabricationUnit) {
}
#-------------------------------------------------------------
# MASS STORAGE STRUCTURES
#-------------------------------------------------------------
TMassStorageUnit = Class(MassStorageUnit) {
}
#-------------------------------------------------------------
# MOBILE FACTORY UNIT
#-------------------------------------------------------------
TMobileFactoryUnit = Class(LandUnit) {
}
#-------------------------------------------------------------
# RADAR STRUCTURES
#-------------------------------------------------------------
TRadarUnit = Class(RadarUnit) {
}
#-------------------------------------------------------------
# SONAR STRUCTURES
#-------------------------------------------------------------
TSonarUnit = Class(SonarUnit) {
}
#-------------------------------------------------------------
# SEA FACTORY STRUCTURES
#-------------------------------------------------------------
TSeaFactoryUnit = Class(SeaFactoryUnit) {
CreateBuildEffects = function( self, unitBeingBuilt, order )
WaitSeconds( 0.1 )
for k, v in self.BuildBones.BuildEffectBones do
self.BuildEffectsBag:Add( CreateAttachedEmitter( self, v, self:GetArmy(), '/effects/emitters/flashing_blue_glow_01_emit.bp' ) )
self.BuildEffectsBag:Add( self:ForkThread( EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag ) )
end
end,
OnPaused = function(self)
SeaFactoryUnit.OnPaused(self)
self:StopArmsMoving()
end,
OnUnpaused = function(self)
SeaFactoryUnit.OnUnpaused(self)
if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
self:StartArmsMoving()
end
end,
OnStartBuild = function(self, unitBeingBuilt, order )
SeaFactoryUnit.OnStartBuild(self, unitBeingBuilt, order )
if order != 'Upgrade' then
self:StartArmsMoving()
end
end,
OnStopBuild = function(self, unitBuilding)
SeaFactoryUnit.OnStopBuild(self, unitBuilding)
self:StopArmsMoving()
end,
OnFailedToBuild = function(self)
SeaFactoryUnit.OnFailedToBuild(self)
self:StopArmsMoving()
end,
StartArmsMoving = function(self)
self.ArmsThread = self:ForkThread(self.MovingArmsThread)
end,
MovingArmsThread = function(self)
end,
StopArmsMoving = function(self)
if self.ArmsThread then
KillThread(self.ArmsThread)
self.ArmsThread = nil
end
end,
}
#-------------------------------------------------------------
# SEA UNITS
#-------------------------------------------------------------
TSeaUnit = Class(SeaUnit) {}
#-------------------------------------------------------------
# SHIELD LAND UNITS
#-------------------------------------------------------------
TShieldLandUnit = Class(ShieldLandUnit) {}
#-------------------------------------------------------------
# SHIELD STRUCTURES
#-------------------------------------------------------------
TShieldStructureUnit = Class(ShieldStructureUnit) {
StartBeingBuiltEffects = function(self,builder,layer)
self:SetMesh(self:GetBlueprint().Display.BuildMeshBlueprint, true)
if builder and EntityCategoryContains(categories.MOBILE, builder) then
self:HideBone(0, true)
self.OnBeingBuiltEffectsBag:Add( self:ForkThread( CreateBuildCubeThread, builder, self.OnBeingBuiltEffectsBag ) )
end
end,
}
#-------------------------------------------------------------
# STRUCTURES
#-------------------------------------------------------------
TStructureUnit = Class(StructureUnit) {
}
TRadarJammerUnit = Class(RadarJammerUnit) {
OnIntelEnabled = function(self)
if not self.MySpinner then
self.MySpinner = CreateRotator(self, 'Spinner', 'y', nil, 0, 45, 180)
self.Trash:Add(self.MySpinner)
end
RadarJammerUnit.OnIntelEnabled(self)
self.MySpinner:SetTargetSpeed(180)
end,
OnIntelDisabled = function(self)
RadarJammerUnit.OnIntelDisabled(self)
self.MySpinner:SetTargetSpeed(0)
end,
}
#-------------------------------------------------------------
# SUBMARINE UNITS
#-------------------------------------------------------------
TSubUnit = Class(SubUnit) {}
#-------------------------------------------------------------
# TRANSPORT BEACON UNITS
#-------------------------------------------------------------
TTransportBeaconUnit = Class(DefaultUnitsFile.TransportBeaconUnit) {}
#-------------------------------------------------------------
# WALKING LAND UNITS
#-------------------------------------------------------------
TWalkingLandUnit = Class(WalkingLandUnit) {
WalkingAnimRate = 1,
IdleAnimRate = 1,
DisabledBones = {},
}
#-------------------------------------------------------------
# WALL STRUCTURES
#-------------------------------------------------------------
TWallStructureUnit = Class(WallStructureUnit) {
}
#-------------------------------------------------------------
# CIVILIAN STRUCTURES
#-------------------------------------------------------------
TCivilianStructureUnit = Class(StructureUnit) {}
#-------------------------------------------------------------
# QUANTUM GATE UNITS
#-------------------------------------------------------------
TQuantumGateUnit = Class(QuantumGateUnit) {
}