forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproptree.lua
233 lines (196 loc) · 7.06 KB
/
proptree.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#****************************************************************************
#**
#** File : /lua/proptree.lua
#**
#** Summary : Class for tree props that can burn and fall down and such
#**
#** Copyright 2006 Gas Powered Games, Inc. All rights reserved.
#****************************************************************************
local Prop = import('/lua/sim/Prop.lua').Prop
local FireEffects = import('/lua/EffectTemplates.lua').TreeBurning01
local DefaultExplosions = import('/lua/defaultexplosions.lua')
local GetRandomFloat = import('/lua/utilities.lua').GetRandomFloat
Tree = Class(Prop) {
OnCollisionCheck = function(self, other)
return true
end,
OnCollision = function(self, other, nx, ny, nz, depth)
self.Motor = self.Motor or self:FallDown()
self.Motor:Whack(nx, ny, nz, depth, true)
self:PlayUprootingEffect(other)
ChangeState(self, self.FallingState)
end,
OnDamage = function(self, instigator, armormod, direction, type)
Prop.OnDamage(self, instigator, armormod, direction, type)
if type == 'Force' then
self.Motor = self.Motor or self:FallDown()
self.Motor:Whack(direction[1], direction[2], direction[3], 1, true)
local bp = self:GetBlueprint()
self:SetMesh(bp.Display.MeshBlueprintWrecked)
ChangeState(self, self.FallingState)
elseif type == 'Nuke' then
if Random(1, 250) < 5 then
ChangeState(self, self.BurningState)
self.BurnFromNuke = true
end
elseif type == 'Disintegrate' then
self:Destroy()
else
if Random(1, 8) <= 1 then
ChangeState(self, self.BurningState)
end
end
end,
OnKilled = function(self)
Prop.OnKilled(self)
ChangeState(self, self.DeadState)
end,
OnDestroy = function(self)
Prop.OnDestroy(self)
ChangeState(self, self.DeadState)
end,
PlayUprootingEffect = function(self, instigator)
local pos = self:GetCachePosition()
local army = -1
if instigator then
army = instigator:GetArmy()
end
local TerrainType = GetTerrainType( pos.x,pos.z )
if TerrainType.FXOther.Land.TreeRootDirt01 == nil then
TerrainType = GetTerrainType( -1, -1 )
end
if TerrainType.FXOther.Land.TreeRootDirt01 != nil then
for k, v in TerrainType.FXOther.Land.TreeRootDirt01 do
CreateEmitterAtEntity( self, army, v )
end
end
self:PlayPropSound('TreeFall')
end,
BurningState = State {
Main = function(self)
local effects = {}
local fx
local bp = self:GetBlueprint()
for k, v in FireEffects do
fx = CreateEmitterAtEntity(self, -1, v ):OffsetEmitter(0, 0.5, 0):ScaleEmitter(4)
table.insert(effects, fx)
self.Trash:Add(fx)
end
fx = CreateLightParticleIntel( self, -1, -1, 1.5, 10, 'glow_03', 'ramp_flare_02' )
table.insert(effects, fx)
self.Trash:Add(fx)
self:PlayPropSound('BurnStart')
self:PlayPropAmbientSound('BurnLoop')
WaitSeconds(0.5)
self:SetMesh(bp.Display.MeshBlueprintWrecked)
for i = 5, 1, -1 do
for k, v in effects do
v:Destroy()
end
for k, v in FireEffects do
local fx = CreateAttachedEmitter(self, -2, -1, v ):OffsetEmitter(0, 0, 0.3):ScaleEmitter(i * 0.5)
table.insert(effects, fx)
self.Trash:Add(fx)
end
WaitSeconds(3 + Random(1, 10) * 0.1)
if not self.BurnFromNuke and i == 3 then
DamageArea(self, self:GetCachePosition(), 1, 1, 'Fire', true)
end
end
self.Motor = self.Motor or self:FallDown()
self.Motor:Whack(GetRandomFloat(-1, 1), 0, GetRandomFloat(-1, 1), 0.25, true)
WaitSeconds(5)
DefaultExplosions.CreateScorchMarkSplat( self, 0.5, -1 )
DamageArea(self, self:GetCachePosition(), 1, 1, 'Fire', true)
self:PlayPropAmbientSound(nil)
for k, v in effects do
v:Destroy()
end
self:SinkAway(-.1)
self.Motor = nil
WaitSeconds(10)
self:Destroy()
end,
OnCollisionCheck = function(self, other)
if IsUnit(other) then
return true
else
return false
end
end,
OnCollision = function(self, other, nx, ny, nz, depth)
self.Motor = self.Motor or self:FallDown()
local otherbp = other:GetBlueprint()
local is_big = (otherbp.SizeX * otherbp.SizeZ) > 0.2
if is_big then
self.Motor:Whack(nx, ny, nz, depth, true)
else
self.Motor:Whack(nx, ny, nz, .05, false)
end
end,
OnDamage = function(self, instigator, armormod, direction, type)
if type == 'Force' then
self.Motor = self:FallDown()
self.Motor:Whack(direction[1], direction[2], direction[3], 1, true)
elseif type == 'Disintegrate' then
self:Destroy()
end
end,
},
FallingState = State {
Main = function(self)
local bp = self:GetBlueprint()
WaitSeconds(30)
self:SinkAway(-.1)
self.Motor = nil
WaitSeconds(10)
self:Destroy()
end,
OnDamage = function(self, instigator, armormod, direction, type)
if type == 'Disintegrate' then
self:Destroy()
end
end,
},
DeadState = State {
Main = function(self)
end,
OnCollisionCheck = function(self, other)
return false
end,
OnCollision = function(self, other, nx, ny, nz, depth)
end,
OnDamage = function(self, instigator, armormod, direction, type)
end,
},
}
TreeGroup = Class(Prop) {
OnCollisionCheck = function(self, other)
self:Breakup()
return false
end,
OnCollision = function(self, other, vec)
self:Breakup()
end,
OnDamage = function(self, instigator, armormod, direction, type)
if type != 'Force' then
if Random(1, 10) <= 1 then
self:Breakup()
end
else
self:Breakup()
end
end,
Breakup = function(self)
if self:BeenDestroyed() then
return
end
# If the blueprint defines a SingleTreeBlueprint, we turn every bone into
# a copy of that blueprint
if self:GetBlueprint().SingleTreeBlueprint then
return SplitProp(self, self:GetBlueprint().SingleTreeBlueprint)
end
# Otherwise, we use the bone names to create a different prop for each bone
return self:SplitOnBonesByName(self:GetBlueprint().SingleTreeDir)
end,
}