author | unc0rr |
Thu, 20 Mar 2014 22:14:30 +0400 | |
changeset 10211 | f4c51ab8f46d |
parent 10193 | d7cd5b43588f |
child 10251 | a3b42e81803c |
permissions | -rw-r--r-- |
9287 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
9287 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10015
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
9287 | 17 |
*) |
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uVisualGearsList; |
|
22 |
interface |
|
23 |
uses uTypes; |
|
24 |
||
25 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
|
26 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord): PVisualGear; inline; |
|
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
27 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean): PVisualGear; inline; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
28 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean; Layer: LongInt): PVisualGear; |
9287 | 29 |
procedure DeleteVisualGear(Gear: PVisualGear); |
30 |
function VisualGearByUID(uid : Longword) : PVisualGear; |
|
31 |
||
10015 | 32 |
const |
9287 | 33 |
cExplFrameTicks = 110; |
34 |
||
35 |
var VGCounter: LongWord; |
|
36 |
VisualGearLayers: array[0..6] of PVisualGear; |
|
37 |
||
38 |
implementation |
|
39 |
uses uFloat, uVariables, uConsts, uTextures, uVisualGearsHandlers; |
|
40 |
||
41 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
|
42 |
begin |
|
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
43 |
AddVisualGear:= AddVisualGear(X, Y, Kind, 0, false, -1); |
9287 | 44 |
end; |
45 |
||
46 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord): PVisualGear; inline; |
|
47 |
begin |
|
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
48 |
AddVisualGear:= AddVisualGear(X, Y, Kind, State, false, -1); |
9287 | 49 |
end; |
50 |
||
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
51 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean): PVisualGear; inline; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
52 |
begin |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
53 |
AddVisualGear:= AddVisualGear(X, Y, Kind, State, Critical, -1); |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
54 |
end; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
55 |
|
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
56 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean; Layer: LongInt): PVisualGear; |
9287 | 57 |
var gear: PVisualGear; |
58 |
t: Longword; |
|
59 |
sp: real; |
|
60 |
begin |
|
61 |
AddVisualGear:= nil; |
|
62 |
if ((GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) or fastScrolling) and // we are scrolling now |
|
63 |
((Kind <> vgtCloud) and (not Critical)) then |
|
64 |
exit; |
|
65 |
||
66 |
if ((cReducedQuality and rqAntiBoom) <> 0) and |
|
67 |
(not Critical) and |
|
68 |
(not (Kind in |
|
69 |
[vgtTeamHealthSorter, |
|
70 |
vgtSmallDamageTag, |
|
71 |
vgtSpeechBubble, |
|
72 |
vgtHealthTag, |
|
73 |
vgtExplosion, |
|
74 |
vgtSmokeTrace, |
|
75 |
vgtEvilTrace, |
|
76 |
vgtNote, |
|
77 |
vgtSmoothWindBar])) then |
|
10015 | 78 |
|
9287 | 79 |
exit; |
80 |
||
81 |
inc(VGCounter); |
|
82 |
New(gear); |
|
83 |
FillChar(gear^, sizeof(TVisualGear), 0); |
|
84 |
gear^.X:= real(X); |
|
85 |
gear^.Y:= real(Y); |
|
86 |
gear^.Kind := Kind; |
|
9960 | 87 |
gear^.doStep:= doStepVGHandlers[Kind]; |
9287 | 88 |
gear^.Tint:= $FFFFFFFF; |
89 |
gear^.uid:= VGCounter; |
|
90 |
||
91 |
with gear^ do |
|
92 |
case Kind of |
|
93 |
vgtFlake: |
|
94 |
begin |
|
95 |
Timer:= 0; |
|
96 |
tdX:= 0; |
|
97 |
tdY:= 0; |
|
98 |
Scale:= 1.0; |
|
99 |
if SuddenDeathDmg then |
|
100 |
begin |
|
101 |
FrameTicks:= random(vobSDFrameTicks); |
|
102 |
Frame:= random(vobSDFramesCount); |
|
103 |
end |
|
104 |
else |
|
105 |
begin |
|
106 |
FrameTicks:= random(vobFrameTicks); |
|
107 |
Frame:= random(vobFramesCount); |
|
108 |
end; |
|
109 |
Angle:= random(360); |
|
110 |
dx:= 0.0000038654705 * random(10000); |
|
111 |
dy:= 0.000003506096 * random(7000); |
|
112 |
if random(2) = 0 then |
|
113 |
dx := -dx; |
|
114 |
if SuddenDeathDmg then |
|
115 |
dAngle:= (random(2) * 2 - 1) * (vobSDVelocity + random(vobSDVelocity)) / 1000 |
|
116 |
else |
|
117 |
dAngle:= (random(2) * 2 - 1) * (vobVelocity + random(vobVelocity)) / 1000 |
|
118 |
end; |
|
119 |
vgtCloud: |
|
120 |
begin |
|
121 |
Frame:= random(4); |
|
122 |
dx:= 0.5 + 0.1 * random(5); // how much the cloud will be affected by wind |
|
123 |
timer:= random(4096); |
|
124 |
Scale:= 1.0 |
|
125 |
end; |
|
126 |
vgtExplPart, |
|
127 |
vgtExplPart2: |
|
128 |
begin |
|
129 |
t:= random(1024); |
|
130 |
sp:= 0.001 * (random(95) + 70); |
|
131 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
132 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
133 |
if random(2) = 0 then |
|
134 |
dx := -dx; |
|
135 |
if random(2) = 0 then |
|
136 |
dy := -dy; |
|
137 |
Frame:= 7 - random(3); |
|
138 |
FrameTicks:= cExplFrameTicks |
|
139 |
end; |
|
140 |
vgtFire: |
|
141 |
begin |
|
142 |
t:= random(1024); |
|
143 |
sp:= 0.001 * (random(85) + 95); |
|
144 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
145 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
146 |
if random(2) = 0 then |
|
147 |
dx := -dx; |
|
148 |
if random(2) = 0 then |
|
149 |
dy := -dy; |
|
150 |
FrameTicks:= 650 + random(250); |
|
151 |
Frame:= random(8) |
|
152 |
end; |
|
153 |
vgtEgg: |
|
154 |
begin |
|
155 |
t:= random(1024); |
|
156 |
sp:= 0.001 * (random(85) + 95); |
|
157 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
158 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
159 |
if random(2) = 0 then |
|
160 |
dx := -dx; |
|
161 |
if random(2) = 0 then |
|
162 |
dy := -dy; |
|
163 |
FrameTicks:= 650 + random(250); |
|
164 |
Frame:= 1 |
|
165 |
end; |
|
166 |
vgtShell: FrameTicks:= 500; |
|
167 |
vgtSmallDamageTag: |
|
168 |
begin |
|
169 |
gear^.FrameTicks:= 1100 |
|
170 |
end; |
|
171 |
vgtBubble: |
|
172 |
begin |
|
173 |
dx:= 0.0000038654705 * random(10000); |
|
174 |
dy:= 0; |
|
175 |
if random(2) = 0 then |
|
176 |
dx := -dx; |
|
177 |
FrameTicks:= 250 + random(1751); |
|
178 |
Frame:= random(5) |
|
179 |
end; |
|
180 |
vgtSteam: |
|
181 |
begin |
|
182 |
dx:= 0.0000038654705 * random(10000); |
|
183 |
dy:= 0.001 * (random(85) + 95); |
|
184 |
if random(2) = 0 then |
|
185 |
dx := -dx; |
|
186 |
Frame:= 7 - random(3); |
|
187 |
FrameTicks:= cExplFrameTicks * 2; |
|
188 |
end; |
|
189 |
vgtAmmo: |
|
190 |
begin |
|
191 |
alpha:= 1.0; |
|
192 |
scale:= 1.0 |
|
193 |
end; |
|
194 |
vgtSmokeWhite, |
|
195 |
vgtSmoke: |
|
196 |
begin |
|
197 |
Scale:= 1.0; |
|
198 |
dx:= 0.0002 * (random(45) + 10); |
|
199 |
dy:= 0.0002 * (random(45) + 10); |
|
200 |
if random(2) = 0 then |
|
201 |
dx := -dx; |
|
202 |
Frame:= 7 - random(2); |
|
203 |
FrameTicks:= cExplFrameTicks * 2; |
|
204 |
end; |
|
205 |
vgtDust: |
|
206 |
begin |
|
207 |
dx:= 0.005 * (random(15) + 10); |
|
208 |
dy:= 0.001 * (random(40) + 20); |
|
209 |
if random(2) = 0 then dx := -dx; |
|
210 |
if random(2) = 0 then Tag:= 1 |
|
211 |
else Tag:= -1; |
|
212 |
Frame:= 7 - random(2); |
|
213 |
FrameTicks:= random(20) + 15; |
|
214 |
end; |
|
215 |
vgtSplash: |
|
216 |
begin |
|
217 |
dx:= 0; |
|
218 |
dy:= 0; |
|
219 |
FrameTicks:= 740; |
|
220 |
Frame:= 19; |
|
221 |
Scale:= 0.75; |
|
222 |
Timer:= 1; |
|
223 |
end; |
|
224 |
vgtDroplet: |
|
225 |
begin |
|
226 |
dx:= 0.001 * (random(180) - 90); |
|
227 |
dy:= -0.001 * (random(160) + 40); |
|
228 |
FrameTicks:= 250 + random(1751); |
|
229 |
Frame:= random(3) |
|
230 |
end; |
|
231 |
vgtBeeTrace: |
|
232 |
begin |
|
233 |
FrameTicks:= 1000; |
|
234 |
Frame:= random(16); |
|
235 |
end; |
|
236 |
vgtSmokeRing: |
|
237 |
begin |
|
238 |
dx:= 0; |
|
239 |
dy:= 0; |
|
240 |
FrameTicks:= 600; |
|
241 |
Timer:= 0; |
|
242 |
Frame:= 0; |
|
243 |
scale:= 0.6; |
|
244 |
alpha:= 1; |
|
245 |
angle:= random(360); |
|
246 |
end; |
|
247 |
vgtFeather: |
|
248 |
begin |
|
249 |
t:= random(1024); |
|
250 |
sp:= 0.001 * (random(85) + 95); |
|
251 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
252 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
253 |
if random(2) = 0 then |
|
254 |
dx := -dx; |
|
255 |
if random(2) = 0 then |
|
256 |
dy := -dy; |
|
257 |
FrameTicks:= 650 + random(250); |
|
258 |
Frame:= 1 |
|
259 |
end; |
|
260 |
vgtHealthTag: |
|
261 |
begin |
|
262 |
Frame:= 0; |
|
263 |
Timer:= 1500; |
|
264 |
dY:= -0.08; |
|
265 |
dX:= 0; |
|
266 |
//gear^.Z:= 2002; |
|
267 |
end; |
|
268 |
vgtSmokeTrace, |
|
269 |
vgtEvilTrace: |
|
270 |
begin |
|
271 |
gear^.X:= gear^.X - 16; |
|
272 |
gear^.Y:= gear^.Y - 16; |
|
273 |
gear^.State:= 8; |
|
274 |
//gear^.Z:= cSmokeZ |
|
275 |
end; |
|
276 |
vgtBigExplosion: |
|
277 |
begin |
|
278 |
gear^.Angle:= random(360); |
|
279 |
end; |
|
280 |
vgtChunk: |
|
281 |
begin |
|
282 |
gear^.Frame:= random(4); |
|
283 |
t:= random(1024); |
|
284 |
sp:= 0.001 * (random(85) + 47); |
|
285 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
286 |
dy:= hwFloat2Float(AngleCos(t)) * sp * -2; |
|
287 |
if random(2) = 0 then |
|
288 |
dx := -dx; |
|
289 |
end; |
|
10015 | 290 |
vgtNote: |
9287 | 291 |
begin |
292 |
dx:= 0.005 * (random(15) + 10); |
|
293 |
dy:= -0.001 * (random(40) + 20); |
|
294 |
if random(2) = 0 then |
|
295 |
dx := -dx; |
|
296 |
Frame:= random(4); |
|
297 |
FrameTicks:= random(2000) + 1500; |
|
298 |
end; |
|
299 |
vgtBulletHit: |
|
300 |
begin |
|
301 |
dx:= 0; |
|
302 |
dy:= 0; |
|
303 |
FrameTicks:= 350; |
|
304 |
Frame:= 7; |
|
305 |
Angle:= 0; |
|
306 |
end; |
|
10015 | 307 |
vgtSmoothWindBar: |
9287 | 308 |
begin |
309 |
Angle:= hwFloat2Float(cMaxWindSpeed)*2 / 1440; // seems rate below is supposed to change wind bar at 1px per 10ms. Max time, 1440ms. This tries to match the rate of change |
|
310 |
Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
|
311 |
end; |
|
312 |
vgtStraightShot: |
|
313 |
begin |
|
314 |
Angle:= 0; |
|
315 |
Scale:= 1.0; |
|
316 |
dx:= 0.001 * random(45); |
|
317 |
dy:= 0.001 * (random(20) + 25); |
|
318 |
State:= ord(sprHealth); |
|
319 |
if random(2) = 0 then |
|
320 |
dx := -dx; |
|
321 |
Frame:= 0; |
|
322 |
FrameTicks:= random(750) + 1250; |
|
323 |
State:= ord(sprSnowDust); |
|
324 |
end; |
|
325 |
end; |
|
326 |
||
327 |
if State <> 0 then |
|
328 |
gear^.State:= State; |
|
329 |
||
330 |
case Gear^.Kind of |
|
331 |
vgtFlake: if cFlattenFlakes then |
|
332 |
gear^.Layer:= 0 |
|
10015 | 333 |
else if random(3) = 0 then |
9287 | 334 |
begin |
335 |
gear^.Scale:= 0.5; |
|
336 |
gear^.Layer:= 0 // 33% - far back |
|
337 |
end |
|
338 |
else if random(3) = 0 then |
|
339 |
begin |
|
340 |
gear^.Scale:= 0.8; |
|
341 |
gear^.Layer:= 4 // 22% - mid-distance |
|
342 |
end |
|
343 |
else if random(3) <> 0 then |
|
344 |
gear^.Layer:= 5 // 30% - just behind land |
|
345 |
else if random(2) = 0 then |
|
346 |
gear^.Layer:= 6 // 7% - just in front of land |
|
347 |
else |
|
348 |
begin |
|
349 |
gear^.Scale:= 1.5; |
|
350 |
gear^.Layer:= 2; // 7% - close up |
|
351 |
end; |
|
352 |
||
353 |
vgtCloud: if cFlattenClouds then gear^.Layer:= 5 |
|
354 |
else if random(3) = 0 then |
|
355 |
begin |
|
356 |
gear^.Scale:= 0.25; |
|
357 |
gear^.Layer:= 0 |
|
358 |
end |
|
359 |
else if random(2) = 0 then |
|
360 |
gear^.Layer:= 5 |
|
361 |
else |
|
362 |
begin |
|
363 |
gear^.Scale:= 0.4; |
|
364 |
gear^.Layer:= 4 |
|
365 |
end; |
|
366 |
||
367 |
// 0: this layer is very distant in the background when in stereo |
|
368 |
vgtTeamHealthSorter, |
|
369 |
vgtSmoothWindBar: gear^.Layer:= 0; |
|
370 |
||
371 |
||
372 |
// 1: this layer is on the land level (which is close but behind the screen plane) when stereo |
|
373 |
vgtSmokeTrace, |
|
374 |
vgtEvilTrace, |
|
375 |
vgtLineTrail, |
|
376 |
vgtSmoke, |
|
377 |
vgtSmokeWhite, |
|
378 |
vgtDust, |
|
379 |
vgtFire, |
|
380 |
vgtSplash, |
|
381 |
vgtDroplet, |
|
382 |
vgtBubble: gear^.Layer:= 1; |
|
383 |
||
384 |
// 3: this layer is on the screen plane (depth = 0) when stereo |
|
385 |
vgtSpeechBubble, |
|
386 |
vgtSmallDamageTag, |
|
387 |
vgtHealthTag, |
|
388 |
vgtStraightShot, |
|
389 |
vgtChunk: gear^.Layer:= 3; |
|
390 |
||
391 |
// 2: this layer is outside the screen when stereo |
|
392 |
vgtExplosion, |
|
393 |
vgtBigExplosion, |
|
394 |
vgtExplPart, |
|
395 |
vgtExplPart2, |
|
396 |
vgtSteam, |
|
397 |
vgtAmmo, |
|
398 |
vgtShell, |
|
399 |
vgtFeather, |
|
400 |
vgtEgg, |
|
401 |
vgtBeeTrace, |
|
402 |
vgtSmokeRing, |
|
403 |
vgtNote, |
|
404 |
vgtBulletHit, |
|
405 |
vgtCircle: gear^.Layer:= 2 |
|
406 |
end; |
|
407 |
||
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
408 |
if Layer <> -1 then gear^.Layer:= Layer; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
409 |
|
9287 | 410 |
if VisualGearLayers[gear^.Layer] <> nil then |
411 |
begin |
|
412 |
VisualGearLayers[gear^.Layer]^.PrevGear:= gear; |
|
413 |
gear^.NextGear:= VisualGearLayers[gear^.Layer] |
|
414 |
end; |
|
415 |
VisualGearLayers[gear^.Layer]:= gear; |
|
416 |
||
417 |
AddVisualGear:= gear; |
|
418 |
end; |
|
419 |
||
420 |
procedure DeleteVisualGear(Gear: PVisualGear); |
|
421 |
begin |
|
422 |
FreeTexture(Gear^.Tex); |
|
423 |
Gear^.Tex:= nil; |
|
424 |
||
425 |
if Gear^.NextGear <> nil then |
|
426 |
Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
|
427 |
if Gear^.PrevGear <> nil then |
|
428 |
Gear^.PrevGear^.NextGear:= Gear^.NextGear |
|
429 |
else |
|
430 |
VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; |
|
431 |
||
432 |
if lastVisualGearByUID = Gear then |
|
433 |
lastVisualGearByUID:= nil; |
|
434 |
||
435 |
Dispose(Gear); |
|
436 |
end; |
|
437 |
||
438 |
function VisualGearByUID(uid : Longword) : PVisualGear; |
|
439 |
var vg: PVisualGear; |
|
440 |
i: LongWord; |
|
441 |
begin |
|
442 |
VisualGearByUID:= nil; |
|
443 |
if uid = 0 then |
|
444 |
exit; |
|
445 |
if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then |
|
446 |
begin |
|
447 |
VisualGearByUID:= lastVisualGearByUID; |
|
448 |
exit |
|
449 |
end; |
|
450 |
// search in an order that is more likely to return layers they actually use. Could perhaps track statistically AddVisualGear in uScript, since that is most likely the ones they want |
|
451 |
for i:= 2 to 5 do |
|
452 |
begin |
|
453 |
vg:= VisualGearLayers[i mod 4]; |
|
454 |
while vg <> nil do |
|
455 |
begin |
|
456 |
if vg^.uid = uid then |
|
457 |
begin |
|
458 |
lastVisualGearByUID:= vg; |
|
459 |
VisualGearByUID:= vg; |
|
460 |
exit |
|
461 |
end; |
|
462 |
vg:= vg^.NextGear |
|
463 |
end |
|
464 |
end |
|
465 |
end; |
|
466 |
||
467 |
||
468 |
end. |