author | sheepluva |
Mon, 13 Jan 2014 19:34:39 +0100 | |
changeset 9979 | 710e0f92c2ab |
parent 9769 | 5814e0c47c99 |
child 9960 | fac73b8a52d3 |
child 9998 | 736015b847e3 |
permissions | -rw-r--r-- |
9287 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
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 |
||
32 |
const |
|
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 |
|
78 |
||
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; |
|
87 |
gear^.doStep:= doStepHandlers[Kind]; |
|
88 |
gear^.State:= 0; |
|
89 |
gear^.Tint:= $FFFFFFFF; |
|
90 |
gear^.uid:= VGCounter; |
|
91 |
gear^.Layer:= 0; |
|
92 |
||
93 |
with gear^ do |
|
94 |
case Kind of |
|
95 |
vgtFlake: |
|
96 |
begin |
|
97 |
Timer:= 0; |
|
98 |
tdX:= 0; |
|
99 |
tdY:= 0; |
|
100 |
Scale:= 1.0; |
|
101 |
if SuddenDeathDmg then |
|
102 |
begin |
|
103 |
FrameTicks:= random(vobSDFrameTicks); |
|
104 |
Frame:= random(vobSDFramesCount); |
|
105 |
end |
|
106 |
else |
|
107 |
begin |
|
108 |
FrameTicks:= random(vobFrameTicks); |
|
109 |
Frame:= random(vobFramesCount); |
|
110 |
end; |
|
111 |
Angle:= random(360); |
|
112 |
dx:= 0.0000038654705 * random(10000); |
|
113 |
dy:= 0.000003506096 * random(7000); |
|
114 |
if random(2) = 0 then |
|
115 |
dx := -dx; |
|
116 |
if SuddenDeathDmg then |
|
117 |
dAngle:= (random(2) * 2 - 1) * (vobSDVelocity + random(vobSDVelocity)) / 1000 |
|
118 |
else |
|
119 |
dAngle:= (random(2) * 2 - 1) * (vobVelocity + random(vobVelocity)) / 1000 |
|
120 |
end; |
|
121 |
vgtCloud: |
|
122 |
begin |
|
123 |
Frame:= random(4); |
|
124 |
dx:= 0.5 + 0.1 * random(5); // how much the cloud will be affected by wind |
|
125 |
timer:= random(4096); |
|
126 |
Scale:= 1.0 |
|
127 |
end; |
|
128 |
vgtExplPart, |
|
129 |
vgtExplPart2: |
|
130 |
begin |
|
131 |
t:= random(1024); |
|
132 |
sp:= 0.001 * (random(95) + 70); |
|
133 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
134 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
135 |
if random(2) = 0 then |
|
136 |
dx := -dx; |
|
137 |
if random(2) = 0 then |
|
138 |
dy := -dy; |
|
139 |
Frame:= 7 - random(3); |
|
140 |
FrameTicks:= cExplFrameTicks |
|
141 |
end; |
|
142 |
vgtFire: |
|
143 |
begin |
|
144 |
t:= random(1024); |
|
145 |
sp:= 0.001 * (random(85) + 95); |
|
146 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
147 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
148 |
if random(2) = 0 then |
|
149 |
dx := -dx; |
|
150 |
if random(2) = 0 then |
|
151 |
dy := -dy; |
|
152 |
FrameTicks:= 650 + random(250); |
|
153 |
Frame:= random(8) |
|
154 |
end; |
|
155 |
vgtEgg: |
|
156 |
begin |
|
157 |
t:= random(1024); |
|
158 |
sp:= 0.001 * (random(85) + 95); |
|
159 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
160 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
161 |
if random(2) = 0 then |
|
162 |
dx := -dx; |
|
163 |
if random(2) = 0 then |
|
164 |
dy := -dy; |
|
165 |
FrameTicks:= 650 + random(250); |
|
166 |
Frame:= 1 |
|
167 |
end; |
|
168 |
vgtShell: FrameTicks:= 500; |
|
169 |
vgtSmallDamageTag: |
|
170 |
begin |
|
171 |
gear^.FrameTicks:= 1100 |
|
172 |
end; |
|
173 |
vgtBubble: |
|
174 |
begin |
|
175 |
dx:= 0.0000038654705 * random(10000); |
|
176 |
dy:= 0; |
|
177 |
if random(2) = 0 then |
|
178 |
dx := -dx; |
|
179 |
FrameTicks:= 250 + random(1751); |
|
180 |
Frame:= random(5) |
|
181 |
end; |
|
182 |
vgtSteam: |
|
183 |
begin |
|
184 |
dx:= 0.0000038654705 * random(10000); |
|
185 |
dy:= 0.001 * (random(85) + 95); |
|
186 |
if random(2) = 0 then |
|
187 |
dx := -dx; |
|
188 |
Frame:= 7 - random(3); |
|
189 |
FrameTicks:= cExplFrameTicks * 2; |
|
190 |
end; |
|
191 |
vgtAmmo: |
|
192 |
begin |
|
193 |
alpha:= 1.0; |
|
194 |
scale:= 1.0 |
|
195 |
end; |
|
196 |
vgtSmokeWhite, |
|
197 |
vgtSmoke: |
|
198 |
begin |
|
199 |
Scale:= 1.0; |
|
200 |
dx:= 0.0002 * (random(45) + 10); |
|
201 |
dy:= 0.0002 * (random(45) + 10); |
|
202 |
if random(2) = 0 then |
|
203 |
dx := -dx; |
|
204 |
Frame:= 7 - random(2); |
|
205 |
FrameTicks:= cExplFrameTicks * 2; |
|
206 |
end; |
|
207 |
vgtDust: |
|
208 |
begin |
|
209 |
dx:= 0.005 * (random(15) + 10); |
|
210 |
dy:= 0.001 * (random(40) + 20); |
|
211 |
if random(2) = 0 then dx := -dx; |
|
212 |
if random(2) = 0 then Tag:= 1 |
|
213 |
else Tag:= -1; |
|
214 |
Frame:= 7 - random(2); |
|
215 |
FrameTicks:= random(20) + 15; |
|
216 |
end; |
|
217 |
vgtSplash: |
|
218 |
begin |
|
219 |
dx:= 0; |
|
220 |
dy:= 0; |
|
221 |
FrameTicks:= 740; |
|
222 |
Frame:= 19; |
|
223 |
Scale:= 0.75; |
|
224 |
Timer:= 1; |
|
225 |
end; |
|
226 |
vgtDroplet: |
|
227 |
begin |
|
228 |
dx:= 0.001 * (random(180) - 90); |
|
229 |
dy:= -0.001 * (random(160) + 40); |
|
230 |
FrameTicks:= 250 + random(1751); |
|
231 |
Frame:= random(3) |
|
232 |
end; |
|
233 |
vgtBeeTrace: |
|
234 |
begin |
|
235 |
FrameTicks:= 1000; |
|
236 |
Frame:= random(16); |
|
237 |
end; |
|
238 |
vgtSmokeRing: |
|
239 |
begin |
|
240 |
dx:= 0; |
|
241 |
dy:= 0; |
|
242 |
FrameTicks:= 600; |
|
243 |
Timer:= 0; |
|
244 |
Frame:= 0; |
|
245 |
scale:= 0.6; |
|
246 |
alpha:= 1; |
|
247 |
angle:= random(360); |
|
248 |
end; |
|
249 |
vgtFeather: |
|
250 |
begin |
|
251 |
t:= random(1024); |
|
252 |
sp:= 0.001 * (random(85) + 95); |
|
253 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
254 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
255 |
if random(2) = 0 then |
|
256 |
dx := -dx; |
|
257 |
if random(2) = 0 then |
|
258 |
dy := -dy; |
|
259 |
FrameTicks:= 650 + random(250); |
|
260 |
Frame:= 1 |
|
261 |
end; |
|
262 |
vgtHealthTag: |
|
263 |
begin |
|
264 |
Frame:= 0; |
|
265 |
Timer:= 1500; |
|
266 |
dY:= -0.08; |
|
267 |
dX:= 0; |
|
268 |
//gear^.Z:= 2002; |
|
269 |
end; |
|
270 |
vgtSmokeTrace, |
|
271 |
vgtEvilTrace: |
|
272 |
begin |
|
273 |
gear^.X:= gear^.X - 16; |
|
274 |
gear^.Y:= gear^.Y - 16; |
|
275 |
gear^.State:= 8; |
|
276 |
//gear^.Z:= cSmokeZ |
|
277 |
end; |
|
278 |
vgtBigExplosion: |
|
279 |
begin |
|
280 |
gear^.Angle:= random(360); |
|
281 |
end; |
|
282 |
vgtChunk: |
|
283 |
begin |
|
284 |
gear^.Frame:= random(4); |
|
285 |
t:= random(1024); |
|
286 |
sp:= 0.001 * (random(85) + 47); |
|
287 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
288 |
dy:= hwFloat2Float(AngleCos(t)) * sp * -2; |
|
289 |
if random(2) = 0 then |
|
290 |
dx := -dx; |
|
291 |
end; |
|
292 |
vgtNote: |
|
293 |
begin |
|
294 |
dx:= 0.005 * (random(15) + 10); |
|
295 |
dy:= -0.001 * (random(40) + 20); |
|
296 |
if random(2) = 0 then |
|
297 |
dx := -dx; |
|
298 |
Frame:= random(4); |
|
299 |
FrameTicks:= random(2000) + 1500; |
|
300 |
end; |
|
301 |
vgtBulletHit: |
|
302 |
begin |
|
303 |
dx:= 0; |
|
304 |
dy:= 0; |
|
305 |
FrameTicks:= 350; |
|
306 |
Frame:= 7; |
|
307 |
Angle:= 0; |
|
308 |
end; |
|
309 |
vgtSmoothWindBar: |
|
310 |
begin |
|
311 |
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 |
|
312 |
Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
|
313 |
end; |
|
314 |
vgtStraightShot: |
|
315 |
begin |
|
316 |
Angle:= 0; |
|
317 |
Scale:= 1.0; |
|
318 |
dx:= 0.001 * random(45); |
|
319 |
dy:= 0.001 * (random(20) + 25); |
|
320 |
State:= ord(sprHealth); |
|
321 |
if random(2) = 0 then |
|
322 |
dx := -dx; |
|
323 |
Frame:= 0; |
|
324 |
FrameTicks:= random(750) + 1250; |
|
325 |
State:= ord(sprSnowDust); |
|
326 |
end; |
|
327 |
end; |
|
328 |
||
329 |
if State <> 0 then |
|
330 |
gear^.State:= State; |
|
331 |
||
332 |
case Gear^.Kind of |
|
333 |
vgtFlake: if cFlattenFlakes then |
|
334 |
gear^.Layer:= 0 |
|
335 |
else if random(3) = 0 then |
|
336 |
begin |
|
337 |
gear^.Scale:= 0.5; |
|
338 |
gear^.Layer:= 0 // 33% - far back |
|
339 |
end |
|
340 |
else if random(3) = 0 then |
|
341 |
begin |
|
342 |
gear^.Scale:= 0.8; |
|
343 |
gear^.Layer:= 4 // 22% - mid-distance |
|
344 |
end |
|
345 |
else if random(3) <> 0 then |
|
346 |
gear^.Layer:= 5 // 30% - just behind land |
|
347 |
else if random(2) = 0 then |
|
348 |
gear^.Layer:= 6 // 7% - just in front of land |
|
349 |
else |
|
350 |
begin |
|
351 |
gear^.Scale:= 1.5; |
|
352 |
gear^.Layer:= 2; // 7% - close up |
|
353 |
end; |
|
354 |
||
355 |
vgtCloud: if cFlattenClouds then gear^.Layer:= 5 |
|
356 |
else if random(3) = 0 then |
|
357 |
begin |
|
358 |
gear^.Scale:= 0.25; |
|
359 |
gear^.Layer:= 0 |
|
360 |
end |
|
361 |
else if random(2) = 0 then |
|
362 |
gear^.Layer:= 5 |
|
363 |
else |
|
364 |
begin |
|
365 |
gear^.Scale:= 0.4; |
|
366 |
gear^.Layer:= 4 |
|
367 |
end; |
|
368 |
||
369 |
// 0: this layer is very distant in the background when in stereo |
|
370 |
vgtTeamHealthSorter, |
|
371 |
vgtSmoothWindBar: gear^.Layer:= 0; |
|
372 |
||
373 |
||
374 |
// 1: this layer is on the land level (which is close but behind the screen plane) when stereo |
|
375 |
vgtSmokeTrace, |
|
376 |
vgtEvilTrace, |
|
377 |
vgtLineTrail, |
|
378 |
vgtSmoke, |
|
379 |
vgtSmokeWhite, |
|
380 |
vgtDust, |
|
381 |
vgtFire, |
|
382 |
vgtSplash, |
|
383 |
vgtDroplet, |
|
384 |
vgtBubble: gear^.Layer:= 1; |
|
385 |
||
386 |
// 3: this layer is on the screen plane (depth = 0) when stereo |
|
387 |
vgtSpeechBubble, |
|
388 |
vgtSmallDamageTag, |
|
389 |
vgtHealthTag, |
|
390 |
vgtStraightShot, |
|
391 |
vgtChunk: gear^.Layer:= 3; |
|
392 |
||
393 |
// 2: this layer is outside the screen when stereo |
|
394 |
vgtExplosion, |
|
395 |
vgtBigExplosion, |
|
396 |
vgtExplPart, |
|
397 |
vgtExplPart2, |
|
398 |
vgtSteam, |
|
399 |
vgtAmmo, |
|
400 |
vgtShell, |
|
401 |
vgtFeather, |
|
402 |
vgtEgg, |
|
403 |
vgtBeeTrace, |
|
404 |
vgtSmokeRing, |
|
405 |
vgtNote, |
|
406 |
vgtBulletHit, |
|
407 |
vgtCircle: gear^.Layer:= 2 |
|
408 |
end; |
|
409 |
||
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
|
410 |
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
|
411 |
|
9287 | 412 |
if VisualGearLayers[gear^.Layer] <> nil then |
413 |
begin |
|
414 |
VisualGearLayers[gear^.Layer]^.PrevGear:= gear; |
|
415 |
gear^.NextGear:= VisualGearLayers[gear^.Layer] |
|
416 |
end; |
|
417 |
VisualGearLayers[gear^.Layer]:= gear; |
|
418 |
||
419 |
AddVisualGear:= gear; |
|
420 |
end; |
|
421 |
||
422 |
procedure DeleteVisualGear(Gear: PVisualGear); |
|
423 |
begin |
|
424 |
FreeTexture(Gear^.Tex); |
|
425 |
Gear^.Tex:= nil; |
|
426 |
||
427 |
if Gear^.NextGear <> nil then |
|
428 |
Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
|
429 |
if Gear^.PrevGear <> nil then |
|
430 |
Gear^.PrevGear^.NextGear:= Gear^.NextGear |
|
431 |
else |
|
432 |
VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; |
|
433 |
||
434 |
if lastVisualGearByUID = Gear then |
|
435 |
lastVisualGearByUID:= nil; |
|
436 |
||
437 |
Dispose(Gear); |
|
438 |
end; |
|
439 |
||
440 |
function VisualGearByUID(uid : Longword) : PVisualGear; |
|
441 |
var vg: PVisualGear; |
|
442 |
i: LongWord; |
|
443 |
begin |
|
444 |
VisualGearByUID:= nil; |
|
445 |
if uid = 0 then |
|
446 |
exit; |
|
447 |
if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then |
|
448 |
begin |
|
449 |
VisualGearByUID:= lastVisualGearByUID; |
|
450 |
exit |
|
451 |
end; |
|
452 |
// 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 |
|
453 |
for i:= 2 to 5 do |
|
454 |
begin |
|
455 |
vg:= VisualGearLayers[i mod 4]; |
|
456 |
while vg <> nil do |
|
457 |
begin |
|
458 |
if vg^.uid = uid then |
|
459 |
begin |
|
460 |
lastVisualGearByUID:= vg; |
|
461 |
VisualGearByUID:= vg; |
|
462 |
exit |
|
463 |
end; |
|
464 |
vg:= vg^.NextGear |
|
465 |
end |
|
466 |
end |
|
467 |
end; |
|
468 |
||
469 |
||
470 |
end. |