hedgewars/uVisualGears.pas
author unc0rr
Mon, 09 Mar 2009 20:47:17 +0000
changeset 1879 bb114339eb4e
parent 1869 490005509a7b
child 1906 644f93d8f148
permissions -rw-r--r--
Implement kick from room
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 1047
diff changeset
     2
 * Hedgewars, a free turn based strategy game
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com>
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     4
 *
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     8
 *
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    13
 *
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    17
 *)
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    18
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    19
unit uVisualGears;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    20
interface
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    21
uses SDLh, uConsts, uFloat, GL;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    22
{$INCLUDE options.inc}
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    23
const AllInactive: boolean = false;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    24
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    25
type PVisualGear = ^TVisualGear;
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    26
	TVGearStepProcedure = procedure (Gear: PVisualGear; Steps: Longword);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    27
	TVisualGear = record
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    28
		NextGear, PrevGear: PVisualGear;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    29
		Frame,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    30
		FrameTicks: Longword;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    31
		X : hwFloat;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    32
		Y : hwFloat;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    33
		dX: hwFloat;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    34
		dY: hwFloat;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    35
		mdY: QWord;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    36
		Angle, dAngle: real;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    37
		Kind: TVisualGearType;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    38
		doStep: TVGearStepProcedure;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    39
		Tex: PTexture;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    40
		end;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    41
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    42
function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    43
procedure ProcessVisualGears(Steps: Longword);
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
    44
procedure DrawVisualGears(Layer: LongWord);
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
    45
procedure DeleteVisualGear(Gear: PVisualGear);
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
    46
procedure AddClouds;
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    47
procedure AddDamageTag(X, Y, Damage, Color: LongWord);
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    48
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    49
var VisualGearsList: PVisualGear = nil;
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    50
	vobFrameTicks, vobFramesCount: Longword;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    51
	vobVelocity, vobFallSpeed: LongInt;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    52
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    53
implementation
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    54
uses uWorld, uMisc, uStore;
1047
ca7078116c0c Update explosion graphics
unc0rr
parents: 1046
diff changeset
    55
const cExplFrameTicks = 110;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    56
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    57
procedure AddDamageTag(X, Y, Damage, Color: LongWord);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    58
var s: shortstring;
1729
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    59
	Gear: PVisualGear;
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    60
begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    61
if cAltDamage then
1729
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    62
	begin
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    63
	Gear:= AddVisualGear(X, Y, vgtSmallDamageTag);
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    64
	if Gear <> nil then
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    65
		with Gear^ do
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    66
			begin
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    67
			str(Damage, s);
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    68
			Tex:= RenderStringTex(s, Color, fntSmall);
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    69
			end
a9f2d8564128 Fix engine crash when using alt damage option
unc0rr
parents: 1642
diff changeset
    70
	end
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    71
end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    72
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    73
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
    74
// ==================================================================
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    75
procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    76
begin
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    77
with Gear^ do
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    78
	begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    79
	inc(FrameTicks, Steps);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    80
	if FrameTicks > vobFrameTicks then
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    81
		begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    82
		dec(FrameTicks, vobFrameTicks);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    83
		inc(Frame);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    84
		if Frame = vobFramesCount then Frame:= 0
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    85
		end
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
    86
	end;
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    87
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    88
Gear^.X:= Gear^.X + (cWindSpeed * 200 + Gear^.dX) * Steps;
808
09ffccb9600a Fix arithmetics
unc0rr
parents: 806
diff changeset
    89
Gear^.Y:= Gear^.Y + (Gear^.dY + cGravity * vobFallSpeed) * Steps;
09ffccb9600a Fix arithmetics
unc0rr
parents: 806
diff changeset
    90
Gear^.Angle:= Gear^.Angle + Gear^.dAngle * Steps;
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
    91
1760
55a1edd97911 Fix nemo's large land patch
unc0rr
parents: 1753
diff changeset
    92
if hwRound(Gear^.X) < -cScreenWidth - 64 then Gear^.X:= int2hwFloat(cScreenWidth + LAND_WIDTH) else
55a1edd97911 Fix nemo's large land patch
unc0rr
parents: 1753
diff changeset
    93
if hwRound(Gear^.X) > cScreenWidth + LAND_WIDTH then Gear^.X:= int2hwFloat(-cScreenWidth - 64);
1869
490005509a7b patch by nemo
unc0rr
parents: 1812
diff changeset
    94
// if hwRound(Gear^.Y) < (LAND_HEIGHT - 1024 - 75) then Gear^.Y:= Gear^.Y + int2hwFloat(25); // For if flag is set for flakes rising upwards?
490005509a7b patch by nemo
unc0rr
parents: 1812
diff changeset
    95
if hwRound(Gear^.Y) > (LAND_HEIGHT + 75) then Gear^.Y:= Gear^.Y - int2hwFloat(1024 + 150) // TODO - configure in theme (jellies for example could use limited range)
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    96
end;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
    97
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
    98
procedure doStepCloud(Gear: PVisualGear; Steps: Longword);
1079
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
    99
var i: Longword;
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   100
begin
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   101
Gear^.X:= Gear^.X + (cWindSpeed * 200 + Gear^.dX) * Steps;
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
   102
1079
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   103
for i:= 0 to Steps - 1 do
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   104
	begin
1776
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1762
diff changeset
   105
	if hwRound(Gear^.Y) > LAND_HEIGHT-1184 then // TODO - configure in theme
1079
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   106
		Gear^.dY:= Gear^.dY - _1div50000
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   107
	else
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   108
		Gear^.dY:= Gear^.dY + _1div50000;
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   109
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   110
	Gear^.Y:= Gear^.Y + Gear^.dY
2a4a8a5ca392 Fix clouds shaking up
unc0rr
parents: 1066
diff changeset
   111
	end;
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
   112
1801
bc0c5c21376e Clouds fixes by nemo
unc0rr
parents: 1792
diff changeset
   113
if hwRound(Gear^.X) < -cScreenWidth - 256 then Gear^.X:= int2hwFloat(cScreenWidth + LAND_WIDTH) else
1762
fe79315a0b66 Fix clouds disappearing in the middle of map
unc0rr
parents: 1760
diff changeset
   114
if hwRound(Gear^.X) > cScreenWidth + LAND_WIDTH then Gear^.X:= int2hwFloat(-cScreenWidth - 256)
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   115
end;
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   116
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   117
procedure doStepExpl(Gear: PVisualGear; Steps: Longword);
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   118
begin
1046
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   119
Gear^.X:= Gear^.X + Gear^.dX * Steps;
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   120
1046
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   121
Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   122
//Gear^.dY:= Gear^.dY + cGravity;
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   123
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   124
if Gear^.FrameTicks <= Steps then
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   125
	if Gear^.Frame = 0 then DeleteVisualGear(Gear)
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   126
	else
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   127
		begin
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   128
		dec(Gear^.Frame);
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   129
		Gear^.FrameTicks:= cExplFrameTicks
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   130
		end
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   131
	else dec(Gear^.FrameTicks, Steps)
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   132
end;
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   133
1046
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   134
procedure doStepFire(Gear: PVisualGear; Steps: Longword);
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   135
begin
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   136
Gear^.X:= Gear^.X + Gear^.dX * Steps;
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   137
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   138
Gear^.Y:= Gear^.Y + Gear^.dY * Steps;// + cGravity * (Steps * Steps);
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   139
Gear^.dY:= Gear^.dY + cGravity * Steps;
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   140
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   141
if Gear^.FrameTicks <= Steps then
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   142
	DeleteVisualGear(Gear)
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   143
else
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   144
	dec(Gear^.FrameTicks, Steps)
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   145
end;
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   146
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   147
procedure doStepSmallDamage(Gear: PVisualGear; Steps: Longword);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   148
begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   149
Gear^.Y:= Gear^.Y - _0_02 * Steps;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   150
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   151
if Gear^.FrameTicks <= Steps then
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   152
	DeleteVisualGear(Gear)
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   153
else
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   154
	dec(Gear^.FrameTicks, Steps)
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   155
end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   156
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   157
// ==================================================================
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   158
const doStepHandlers: array[TVisualGearType] of TVGearStepProcedure =
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   159
		(
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   160
			@doStepFlake,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   161
			@doStepCloud,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   162
			@doStepExpl,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   163
			@doStepExpl,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   164
			@doStepFire,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   165
			@doStepSmallDamage
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   166
		);
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   167
805
4d75759b38bd Flakes concept, still need some development
unc0rr
parents: 803
diff changeset
   168
function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   169
var Result: PVisualGear;
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   170
	t: Longword;
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   171
	sp: hwFloat;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   172
begin
1642
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   173
if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then // we're scrolling now
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   174
	if Kind <> vgtCloud then
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   175
		begin
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   176
		AddVisualGear:= nil;
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   177
		exit
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   178
		end;
177b440773de Disable visual gears when quick replaying
unc0rr
parents: 1505
diff changeset
   179
1812
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   180
if cReducedQuality then
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   181
	begin
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   182
	AddVisualGear:= nil;
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   183
	exit
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   184
	end;
3d4692e825e7 'Reduce quality' patch by nemo
unc0rr
parents: 1801
diff changeset
   185
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   186
New(Result);
812
cbc392576990 Fix memory corrupt due to wrong parameter in sizeof()
unc0rr
parents: 808
diff changeset
   187
FillChar(Result^, sizeof(TVisualGear), 0);
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   188
Result^.X:= int2hwFloat(X);
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   189
Result^.Y:= int2hwFloat(Y);
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   190
Result^.Kind := Kind;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   191
Result^.doStep:= doStepHandlers[Kind];
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   192
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   193
with Result^ do
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   194
	case Kind of
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   195
	vgtFlake: begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   196
				FrameTicks:= random(vobFrameTicks);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   197
				Frame:= random(vobFramesCount);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   198
				Angle:= random * 360;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   199
				dx.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   200
				dx.QWordValue:= random(100000000);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   201
				dy.isNegative:= false;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   202
				dy.QWordValue:= random(70000000);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   203
				dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   204
				end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   205
	vgtCloud: begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   206
				Frame:= random(4);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   207
				dx.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   208
				dx.QWordValue:= random(214748364);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   209
				dy.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   210
				dy.QWordValue:= 21474836 + random(64424509);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   211
				mdY:= dy.QWordValue
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   212
				end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   213
	vgtExplPart,
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   214
	vgtExplPart2: begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   215
				t:= random(1024);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   216
				sp:= _0_001 * (random(95) + 70);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   217
				dx:= AngleSin(t) * sp;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   218
				dx.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   219
				dy:= AngleCos(t) * sp;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   220
				dy.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   221
				Frame:= 7 - random(3);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   222
				FrameTicks:= cExplFrameTicks
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   223
				end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   224
		vgtFire: begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   225
				t:= random(1024);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   226
				sp:= _0_001 * (random(85) + 95);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   227
				dx:= AngleSin(t) * sp;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   228
				dx.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   229
				dy:= AngleCos(t) * sp;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   230
				dy.isNegative:= random(2) = 0;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   231
				FrameTicks:= 650 + random(250);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   232
				Frame:= random(8)
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   233
				end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   234
	vgtSmallDamageTag: begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   235
				Result^.FrameTicks:= 1100
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   236
				end;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   237
		end;
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   238
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   239
if VisualGearsList <> nil then
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   240
	begin
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   241
	VisualGearsList^.PrevGear:= Result;
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   242
	Result^.NextGear:= VisualGearsList
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   243
	end;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   244
VisualGearsList:= Result;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   245
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   246
AddVisualGear:= Result
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   247
end;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   248
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   249
procedure DeleteVisualGear(Gear: PVisualGear);
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   250
begin
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   251
if Gear^.Tex <> nil then
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   252
	FreeTexture(Gear^.Tex);
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   253
1041
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   254
if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   255
if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   256
   else VisualGearsList:= Gear^.NextGear;
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   257
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   258
Dispose(Gear)
362b95d49cf4 - Fix previous commit
unc0rr
parents: 945
diff changeset
   259
end;
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   260
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   261
procedure ProcessVisualGears(Steps: Longword);
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   262
var Gear, t: PVisualGear;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   263
begin
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   264
if Steps = 0 then exit;
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   265
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   266
t:= VisualGearsList;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   267
while t <> nil do
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   268
      begin
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   269
      Gear:= t;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   270
      t:= Gear^.NextGear;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   271
      Gear^.doStep(Gear, Steps)
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   272
      end
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   273
end;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   274
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   275
procedure DrawVisualGears(Layer: LongWord);
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   276
var Gear: PVisualGear;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   277
begin
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   278
Gear:= VisualGearsList;
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   279
case Layer of
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   280
	0: while Gear <> nil do
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   281
		begin
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   282
		case Gear^.Kind of
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   283
			vgtFlake: if vobVelocity = 0 then
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   284
						DrawSprite(sprFlake, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Frame)
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   285
					else
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   286
						DrawRotatedF(sprFlake, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   287
			vgtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Frame);
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   288
			end;
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   289
		Gear:= Gear^.NextGear
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   290
		end;
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   291
	1: while Gear <> nil do
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   292
		begin
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   293
		case Gear^.Kind of
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   294
			vgtExplPart: DrawSprite(sprExplPart, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 7 - Gear^.Frame);
1047
ca7078116c0c Update explosion graphics
unc0rr
parents: 1046
diff changeset
   295
			vgtExplPart2: DrawSprite(sprExplPart2, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 7 - Gear^.Frame);
1046
c22d833c3ae2 Better ?? implementation of explosion
unc0rr
parents: 1045
diff changeset
   296
			vgtFire: DrawSprite(sprFlame, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (RealTicks div 64 + Gear^.Frame) mod 8);
1505
3a96e93572cb - Convert small damage tag to visual gears
unc0rr
parents: 1132
diff changeset
   297
			vgtSmallDamageTag: DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
1045
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   298
			end;
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   299
		Gear:= Gear^.NextGear
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   300
		end
ea195268734f Testing explosion particles implementation
unc0rr
parents: 1041
diff changeset
   301
	end
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   302
end;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   303
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   304
procedure AddClouds;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   305
var i: LongInt;
803
3f73901a350a - Use cloud as 'visual gear'
unc0rr
parents: 802
diff changeset
   306
begin
1132
b4c0698fbb6b - Fix problem when clouds number is 0
unc0rr
parents: 1079
diff changeset
   307
for i:= 0 to cCloudsNumber - 1 do
1801
bc0c5c21376e Clouds fixes by nemo
unc0rr
parents: 1792
diff changeset
   308
    AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + (LAND_WIDTH+256)) div (cCloudsNumber + 1)), LAND_HEIGHT-1184, vgtCloud)
802
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   309
end;
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   310
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   311
initialization
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   312
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   313
finalization
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   314
ed5450a89b96 Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
diff changeset
   315
end.