hedgewars/VGSHandlers.inc
branchspacecampaign
changeset 9308 4bddcc1a1450
parent 9296 5cc010e79431
parent 9306 c9978ada9a3d
child 9310 1469147c110f
equal deleted inserted replaced
9296:5cc010e79431 9308:4bddcc1a1450
     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 (*
       
    20  * This file contains the step handlers for visual gears.
       
    21  *
       
    22  * Since the effects of visual gears do not affect the course of the game,
       
    23  * no "synchronization" between players is required.
       
    24  * => The usage of safe functions or data types (e.g. GetRandom() or hwFloat)
       
    25  * is usually not necessary and therefore undesirable.
       
    26  *)
       
    27 
       
    28 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
       
    29 var sign: real;
       
    30     moved: boolean;
       
    31 begin
       
    32 if vobCount = 0 then exit;
       
    33 
       
    34 sign:= 1;
       
    35 with Gear^ do
       
    36     begin
       
    37     inc(FrameTicks, Steps);
       
    38     if not SuddenDeathDmg and (FrameTicks > vobFrameTicks) then
       
    39         begin
       
    40         dec(FrameTicks, vobFrameTicks);
       
    41         inc(Frame);
       
    42         if Frame = vobFramesCount then
       
    43             Frame:= 0
       
    44         end
       
    45     else if SuddenDeathDmg and (FrameTicks > vobSDFrameTicks) then
       
    46         begin
       
    47         dec(FrameTicks, vobSDFrameTicks);
       
    48         inc(Frame);
       
    49         if Frame = vobSDFramesCount then
       
    50             Frame:= 0
       
    51         end;
       
    52     X:= X + (cWindSpeedf * 400 + dX + tdX) * Steps * Gear^.Scale;
       
    53     if SuddenDeathDmg then
       
    54         Y:= Y + (dY + tdY + cGravityf * vobSDFallSpeed) * Steps * Gear^.Scale
       
    55     else
       
    56         Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps * Gear^.Scale;
       
    57     Angle:= Angle + dAngle * Steps;
       
    58     if Angle > 360 then
       
    59         Angle:= Angle - 360
       
    60     else
       
    61         if Angle < - 360 then
       
    62             Angle:= Angle + 360;
       
    63     
       
    64   
       
    65     if (round(X) >= cLeftScreenBorder)
       
    66     and (round(X) <= cRightScreenBorder)
       
    67     and (round(Y) - 75 <= LAND_HEIGHT)
       
    68     and (Timer > 0) and (Timer-Steps > 0) then
       
    69         begin
       
    70         if tdX > 0 then
       
    71             sign := 1
       
    72         else
       
    73             sign:= -1;
       
    74         tdX:= tdX - 0.005*Steps*sign;
       
    75         if ((sign < 0) and (tdX > 0)) or ((sign > 0) and (tdX < 0)) then
       
    76             tdX:= 0;
       
    77         if tdX > 0 then
       
    78             sign := 1
       
    79         else
       
    80             sign:= -1;
       
    81         tdY:= tdY - 0.005*Steps*sign;
       
    82         if ((sign < 0) and (tdY > 0)) or ((sign > 0) and (tdY < 0)) then
       
    83             tdY:= 0;
       
    84         dec(Timer, Steps)
       
    85         end
       
    86     else
       
    87         begin
       
    88         moved:= false;
       
    89         if round(X) < cLeftScreenBorder then
       
    90             begin
       
    91             X:= X + cScreenSpace;
       
    92             moved:= true
       
    93             end
       
    94         else
       
    95             if round(X) > cRightScreenBorder then
       
    96                 begin
       
    97                 X:= X - cScreenSpace;
       
    98                 moved:= true
       
    99                 end;
       
   100             // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards?
       
   101         if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then
       
   102             begin
       
   103             X:= cLeftScreenBorder + random(cScreenSpace);
       
   104             Y:= Y - (1024 + 250 + random(50)); // TODO - configure in theme (jellies for example could use limited range)
       
   105             moved:= true
       
   106             end
       
   107         else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then
       
   108             begin
       
   109             X:= cLeftScreenBorder + random(cScreenSpace);
       
   110             Y:= Y - (1024 + random(25));
       
   111             moved:= true
       
   112             end;
       
   113         if moved then
       
   114             begin
       
   115             Angle:= random(360);
       
   116             dx:= 0.0000038654705 * random(10000);
       
   117             dy:= 0.000003506096 * random(7000);
       
   118             if random(2) = 0 then dx := -dx
       
   119             end;
       
   120         Timer:= 0;
       
   121         tdX:= 0;
       
   122         tdY:= 0
       
   123         end;
       
   124     end;
       
   125 
       
   126 end;
       
   127 
       
   128 ////////////////////////////////////////////////////////////////////////////////
       
   129 procedure doStepBeeTrace(Gear: PVisualGear; Steps: Longword);
       
   130 begin
       
   131 if Gear^.FrameTicks > Steps then
       
   132     dec(Gear^.FrameTicks, Steps)
       
   133 else
       
   134     DeleteVisualGear(Gear);
       
   135 end;
       
   136 
       
   137 ////////////////////////////////////////////////////////////////////////////////
       
   138 procedure doStepCloud(Gear: PVisualGear; Steps: Longword);
       
   139 var s: Longword;
       
   140     t: real;
       
   141 begin
       
   142 Gear^.X:= Gear^.X + (cWindSpeedf * 750 * Gear^.dX * Gear^.Scale) * Steps;
       
   143 
       
   144 // up-and-down-bounce magic
       
   145 s := (GameTicks + Gear^.Timer) mod 4096;
       
   146 t := 8 * Gear^.Scale * hwFloat2Float(AngleSin(s mod 2048));
       
   147 if (s < 2048) then t := -t;
       
   148 
       
   149 Gear^.Y := LAND_HEIGHT - 1184 + LongInt(Gear^.Timer mod 8) + t;
       
   150 
       
   151 if round(Gear^.X) < cLeftScreenBorder then
       
   152     Gear^.X:= Gear^.X + cScreenSpace
       
   153 else
       
   154     if round(Gear^.X) > cRightScreenBorder then
       
   155         Gear^.X:= Gear^.X - cScreenSpace
       
   156 end;
       
   157 
       
   158 ////////////////////////////////////////////////////////////////////////////////
       
   159 procedure doStepExpl(Gear: PVisualGear; Steps: Longword);
       
   160 var s: LongInt;
       
   161 begin
       
   162 s:= min(Steps, cExplFrameTicks);
       
   163 
       
   164 Gear^.X:= Gear^.X + Gear^.dX * s;
       
   165 Gear^.Y:= Gear^.Y + Gear^.dY * s;
       
   166 //Gear^.dY:= Gear^.dY + cGravityf;
       
   167 
       
   168 if Gear^.FrameTicks <= Steps then
       
   169     if Gear^.Frame = 0 then
       
   170         DeleteVisualGear(Gear)
       
   171     else
       
   172         begin
       
   173         dec(Gear^.Frame);
       
   174         Gear^.FrameTicks:= cExplFrameTicks
       
   175         end
       
   176     else dec(Gear^.FrameTicks, Steps)
       
   177 end;
       
   178 
       
   179 ////////////////////////////////////////////////////////////////////////////////
       
   180 procedure doStepNote(Gear: PVisualGear; Steps: Longword);
       
   181 begin
       
   182 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   183 
       
   184 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   185 Gear^.dY:= Gear^.dY + cGravityf * Steps / 2;
       
   186 
       
   187 Gear^.Angle:= Gear^.Angle + (Gear^.Frame + 1) * Steps / 10;
       
   188 while Gear^.Angle > cMaxAngle do
       
   189     Gear^.Angle:= Gear^.Angle - cMaxAngle;
       
   190 
       
   191 if Gear^.FrameTicks <= Steps then
       
   192     DeleteVisualGear(Gear)
       
   193 else
       
   194     dec(Gear^.FrameTicks, Steps)
       
   195 end;
       
   196 
       
   197 ////////////////////////////////////////////////////////////////////////////////
       
   198 procedure doStepLineTrail(Gear: PVisualGear; Steps: Longword);
       
   199 begin
       
   200 Steps := Steps;
       
   201 if Gear^.Timer <= Steps then
       
   202     DeleteVisualGear(Gear)
       
   203 else
       
   204     dec(Gear^.Timer, Steps)
       
   205 end;
       
   206 
       
   207 ////////////////////////////////////////////////////////////////////////////////
       
   208 procedure doStepEgg(Gear: PVisualGear; Steps: Longword);
       
   209 begin
       
   210 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   211 
       
   212 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   213 Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   214 
       
   215 Gear^.Angle:= round(Gear^.Angle + Steps) mod cMaxAngle;
       
   216 
       
   217 if Gear^.FrameTicks <= Steps then
       
   218     begin
       
   219     DeleteVisualGear(Gear);
       
   220     exit
       
   221     end
       
   222 else
       
   223     dec(Gear^.FrameTicks, Steps);
       
   224 
       
   225 if Gear^.FrameTicks < $FF then
       
   226    Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or Gear^.FrameTicks
       
   227 end;
       
   228 
       
   229 ////////////////////////////////////////////////////////////////////////////////
       
   230 procedure doStepFire(Gear: PVisualGear; Steps: Longword);
       
   231 var vgt: PVisualGear;
       
   232 begin
       
   233 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   234 
       
   235 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;// + cGravityf * (Steps * Steps);
       
   236 if (Gear^.State and gstTmpFlag) = 0 then
       
   237     begin
       
   238     Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   239     if ((GameTicks mod 200) < Steps + 1) then
       
   240         begin
       
   241         vgt:= AddVisualGear(round(Gear^.X), round(Gear^.Y), vgtFire);
       
   242         if vgt <> nil then
       
   243             begin
       
   244             vgt^.dx:= 0;
       
   245             vgt^.dy:= 0;
       
   246             vgt^.State:= gstTmpFlag;
       
   247             end;
       
   248         end
       
   249     end
       
   250 else
       
   251     inc(Steps, Steps);
       
   252 
       
   253 if Gear^.FrameTicks <= Steps then
       
   254        DeleteVisualGear(Gear)
       
   255 else
       
   256     dec(Gear^.FrameTicks, Steps)
       
   257 end;
       
   258 
       
   259 ////////////////////////////////////////////////////////////////////////////////
       
   260 procedure doStepShell(Gear: PVisualGear; Steps: Longword);
       
   261 begin
       
   262 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   263 
       
   264 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   265 Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   266 
       
   267 Gear^.Angle:= round(Gear^.Angle + Steps) mod cMaxAngle;
       
   268 
       
   269 if Gear^.FrameTicks <= Steps then
       
   270     DeleteVisualGear(Gear)
       
   271 else
       
   272     dec(Gear^.FrameTicks, Steps)
       
   273 end;
       
   274 
       
   275 procedure doStepSmallDamage(Gear: PVisualGear; Steps: Longword);
       
   276 begin
       
   277 Gear^.Y:= Gear^.Y - 0.02 * Steps;
       
   278 
       
   279 if Gear^.FrameTicks <= Steps then
       
   280     DeleteVisualGear(Gear)
       
   281 else
       
   282     dec(Gear^.FrameTicks, Steps)
       
   283 end;
       
   284 
       
   285 ////////////////////////////////////////////////////////////////////////////////
       
   286 procedure doStepBubble(Gear: PVisualGear; Steps: Longword);
       
   287 begin
       
   288 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   289 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   290 Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
       
   291 Gear^.dX := Gear^.dX / (1.001 * Steps);
       
   292 Gear^.dY := Gear^.dY / (1.001 * Steps);
       
   293 
       
   294 if (Gear^.FrameTicks <= Steps) or (round(Gear^.Y) < cWaterLine) then
       
   295     DeleteVisualGear(Gear)
       
   296 else
       
   297     dec(Gear^.FrameTicks, Steps)
       
   298 end;
       
   299 
       
   300 ////////////////////////////////////////////////////////////////////////////////
       
   301 procedure doStepSteam(Gear: PVisualGear; Steps: Longword);
       
   302 begin
       
   303 Gear^.X:= Gear^.X + (cWindSpeedf * 100 + Gear^.dX) * Steps;
       
   304 Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
       
   305 
       
   306 if Gear^.FrameTicks <= Steps then
       
   307     if Gear^.Frame = 0 then
       
   308         DeleteVisualGear(Gear)
       
   309     else
       
   310         begin
       
   311         if Random(2) = 0 then
       
   312             dec(Gear^.Frame);
       
   313         Gear^.FrameTicks:= cExplFrameTicks
       
   314         end
       
   315 else dec(Gear^.FrameTicks, Steps)
       
   316 end;
       
   317 
       
   318 ////////////////////////////////////////////////////////////////////////////////
       
   319 procedure doStepAmmo(Gear: PVisualGear; Steps: Longword);
       
   320 begin
       
   321 Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
       
   322 
       
   323 Gear^.scale:= Gear^.scale + 0.0025 * Steps;
       
   324 Gear^.alpha:= Gear^.alpha - 0.0015 * Steps;
       
   325 
       
   326 if Gear^.alpha < 0 then
       
   327     DeleteVisualGear(Gear)
       
   328 end;
       
   329 
       
   330 ////////////////////////////////////////////////////////////////////////////////
       
   331 procedure doStepSmoke(Gear: PVisualGear; Steps: Longword);
       
   332 begin
       
   333 Gear^.X:= Gear^.X + (cWindSpeedf + Gear^.dX) * Steps;
       
   334 Gear^.Y:= Gear^.Y - (cDrownSpeedf + Gear^.dY) * Steps;
       
   335 
       
   336 Gear^.dX := Gear^.dX + (cWindSpeedf * 0.3 * Steps);
       
   337 //Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.995);
       
   338 
       
   339 if Gear^.FrameTicks <= Steps then
       
   340     if Gear^.Frame = 0 then
       
   341         DeleteVisualGear(Gear)
       
   342     else
       
   343         begin
       
   344         if Random(2) = 0 then
       
   345             dec(Gear^.Frame);
       
   346         Gear^.FrameTicks:= cExplFrameTicks
       
   347         end
       
   348     else dec(Gear^.FrameTicks, Steps)
       
   349 end;
       
   350 
       
   351 ////////////////////////////////////////////////////////////////////////////////
       
   352 procedure doStepDust(Gear: PVisualGear; Steps: Longword);
       
   353 begin
       
   354 Gear^.X:= Gear^.X + (cWindSpeedf + (cWindSpeedf * 0.03 * Steps) + Gear^.dX) * Steps;
       
   355 Gear^.Y:= Gear^.Y - (Gear^.dY) * Steps;
       
   356 
       
   357 Gear^.dX := Gear^.dX - (Gear^.dX * 0.005 * Steps);
       
   358 Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.001 * Steps);
       
   359 
       
   360 if Gear^.FrameTicks <= Steps then
       
   361     if Gear^.Frame = 0 then
       
   362             DeleteVisualGear(Gear)
       
   363     else
       
   364         begin
       
   365         dec(Gear^.Frame);
       
   366         Gear^.FrameTicks:= cExplFrameTicks
       
   367         end
       
   368     else dec(Gear^.FrameTicks, Steps)
       
   369 end;
       
   370 
       
   371 ////////////////////////////////////////////////////////////////////////////////
       
   372 procedure doStepSplash(Gear: PVisualGear; Steps: Longword);
       
   373 begin
       
   374 if Gear^.FrameTicks <= Steps then
       
   375     DeleteVisualGear(Gear)
       
   376 else
       
   377     dec(Gear^.FrameTicks, Steps);
       
   378 end;
       
   379 
       
   380 ////////////////////////////////////////////////////////////////////////////////
       
   381 procedure doStepDroplet(Gear: PVisualGear; Steps: Longword);
       
   382 begin
       
   383 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   384 
       
   385 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   386 Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   387 
       
   388 if round(Gear^.Y) > cWaterLine then
       
   389     begin
       
   390     DeleteVisualGear(Gear);
       
   391     PlaySound(TSound(ord(sndDroplet1) + Random(3)));
       
   392     end;
       
   393 end;
       
   394 
       
   395 ////////////////////////////////////////////////////////////////////////////////
       
   396 procedure doStepSmokeRing(Gear: PVisualGear; Steps: Longword);
       
   397 begin
       
   398 inc(Gear^.Timer, Steps);
       
   399 if Gear^.Timer >= Gear^.FrameTicks then
       
   400     DeleteVisualGear(Gear)
       
   401 else
       
   402     begin
       
   403     Gear^.scale := 1.25 * (-power(2, -10 * Int(Gear^.Timer)/Gear^.FrameTicks) + 1) + 0.4;
       
   404     Gear^.alpha := 1 - power(Gear^.Timer / 350, 4);
       
   405     if Gear^.alpha < 0 then
       
   406         Gear^.alpha:= 0;
       
   407     end;
       
   408 end;
       
   409 
       
   410 ////////////////////////////////////////////////////////////////////////////////
       
   411 procedure doStepFeather(Gear: PVisualGear; Steps: Longword);
       
   412 begin
       
   413 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   414 
       
   415 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   416 Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   417 
       
   418 Gear^.Angle:= round(Gear^.Angle + Steps) mod cMaxAngle;
       
   419 
       
   420 if Gear^.FrameTicks <= Steps then
       
   421     DeleteVisualGear(Gear)
       
   422 else
       
   423     dec(Gear^.FrameTicks, Steps)
       
   424 end;
       
   425 
       
   426 ////////////////////////////////////////////////////////////////////////////////
       
   427 const cSorterWorkTime = 640;
       
   428 var thexchar: array[0..cMaxTeams] of
       
   429             record
       
   430             dy, ny, dw: LongInt;
       
   431             team: PTeam;
       
   432             SortFactor: QWord;
       
   433             end;
       
   434     currsorter: PVisualGear = nil;
       
   435 
       
   436 procedure doStepTeamHealthSorterWork(Gear: PVisualGear; Steps: Longword);
       
   437 var i, t: LongInt;
       
   438 begin
       
   439 for t:= 1 to min(Steps, Gear^.Timer) do
       
   440     begin
       
   441     dec(Gear^.Timer);
       
   442     if (Gear^.Timer and 15) = 0 then
       
   443         for i:= 0 to Pred(TeamsCount) do
       
   444             with thexchar[i] do
       
   445                 begin
       
   446                 {$WARNINGS OFF}
       
   447                 team^.DrawHealthY:= ny + dy * LongInt(Gear^.Timer) div cSorterWorkTime;
       
   448                 team^.TeamHealthBarWidth:= team^.NewTeamHealthBarWidth + dw * LongInt(Gear^.Timer) div cSorterWorkTime;
       
   449                 {$WARNINGS ON}
       
   450                 end;
       
   451     end;
       
   452 
       
   453 if (Gear^.Timer = 0) or (currsorter <> Gear) then
       
   454     begin
       
   455     if currsorter = Gear then
       
   456         currsorter:= nil;
       
   457     DeleteVisualGear(Gear);
       
   458     exit
       
   459     end
       
   460 end;
       
   461 
       
   462 procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
       
   463 var i: Longword;
       
   464     b: boolean;
       
   465     t: LongInt;
       
   466 begin
       
   467 Steps:= Steps; // avoid compiler hint
       
   468 
       
   469 for t:= 0 to Pred(TeamsCount) do
       
   470     with thexchar[t] do
       
   471         begin
       
   472         team:= TeamsArray[t];
       
   473         dy:= team^.DrawHealthY;
       
   474         dw:= team^.TeamHealthBarWidth - team^.NewTeamHealthBarWidth;
       
   475         if team^.TeamHealth > 0 then
       
   476             begin
       
   477             SortFactor:= team^.Clan^.ClanHealth;
       
   478             SortFactor:= (SortFactor shl  3) + team^.Clan^.ClanIndex;
       
   479             SortFactor:= (SortFactor shl 30) + team^.TeamHealth;
       
   480             end
       
   481         else
       
   482             SortFactor:= 0;
       
   483         end;
       
   484 
       
   485 if TeamsCount > 1 then
       
   486     repeat
       
   487     b:= true;
       
   488     for t:= 0 to TeamsCount - 2 do
       
   489         if (thexchar[t].SortFactor > thexchar[Succ(t)].SortFactor) then
       
   490             begin
       
   491             thexchar[cMaxTeams]:= thexchar[t];
       
   492             thexchar[t]:= thexchar[Succ(t)];
       
   493             thexchar[Succ(t)]:= thexchar[cMaxTeams];
       
   494             b:= false
       
   495             end
       
   496     until b;
       
   497 
       
   498 t:= - 4;
       
   499 for i:= 0 to Pred(TeamsCount) do
       
   500         with thexchar[i] do
       
   501           if team^.TeamHealth > 0 then
       
   502             begin
       
   503             dec(t, team^.HealthTex^.h + 2);
       
   504             ny:= t;
       
   505             dy:= dy - ny
       
   506             end;
       
   507 
       
   508 Gear^.Timer:= cSorterWorkTime;
       
   509 Gear^.doStep:= @doStepTeamHealthSorterWork;
       
   510 currsorter:= Gear;
       
   511 //doStepTeamHealthSorterWork(Gear, Steps)
       
   512 end;
       
   513 
       
   514 ////////////////////////////////////////////////////////////////////////////////
       
   515 procedure doStepSpeechBubbleWork(Gear: PVisualGear; Steps: Longword);
       
   516 begin
       
   517 if Gear^.Timer > Steps then dec(Gear^.Timer, Steps) else Gear^.Timer:= 0;
       
   518 
       
   519 if (Gear^.Hedgehog^.Gear <> nil) then
       
   520     begin
       
   521     Gear^.X:= hwFloat2Float(Gear^.Hedgehog^.Gear^.X) + (Gear^.Tex^.w div 2  - Gear^.FrameTicks);
       
   522     Gear^.Y:= hwFloat2Float(Gear^.Hedgehog^.Gear^.Y) - (16 + Gear^.Tex^.h);
       
   523     end;
       
   524 
       
   525 if Gear^.Timer = 0 then
       
   526     begin
       
   527     if Gear^.Hedgehog^.SpeechGear = Gear then
       
   528         Gear^.Hedgehog^.SpeechGear:= nil;
       
   529     DeleteVisualGear(Gear)
       
   530     end;
       
   531 end;
       
   532 
       
   533 procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);
       
   534 begin
       
   535 Steps:= Steps; // avoid compiler hint
       
   536 
       
   537 with Gear^.Hedgehog^ do
       
   538     if SpeechGear <> nil then
       
   539         SpeechGear^.Timer:= 0;
       
   540 
       
   541 Gear^.Hedgehog^.SpeechGear:= Gear;
       
   542 
       
   543 Gear^.Timer:= max(LongInt(Length(Gear^.Text)) * 150, 3000);
       
   544 
       
   545 Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);
       
   546 
       
   547 case Gear^.FrameTicks of
       
   548     1: Gear^.FrameTicks:= SpritesData[sprSpeechTail].Width-28;
       
   549     2: Gear^.FrameTicks:= SpritesData[sprThoughtTail].Width-20;
       
   550     3: Gear^.FrameTicks:= SpritesData[sprShoutTail].Width-10;
       
   551     end;
       
   552 
       
   553 Gear^.doStep:= @doStepSpeechBubbleWork;
       
   554 
       
   555 Gear^.Y:= Gear^.Y - Gear^.Tex^.h
       
   556 end;
       
   557 
       
   558 ////////////////////////////////////////////////////////////////////////////////
       
   559 procedure doStepHealthTagWork(Gear: PVisualGear; Steps: Longword);
       
   560 begin
       
   561 if Steps > Gear^.Timer then
       
   562     DeleteVisualGear(Gear)
       
   563 else
       
   564     begin
       
   565     dec(Gear^.Timer, Steps);
       
   566     Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   567     Gear^.X:= Gear^.X + Gear^.dX * Steps
       
   568     end;
       
   569 end;
       
   570 
       
   571 procedure doStepHealthTagWorkUnderWater(Gear: PVisualGear; Steps: Longword);
       
   572 begin
       
   573 if round(Gear^.Y) - 10 < cWaterLine then
       
   574     DeleteVisualGear(Gear)
       
   575 else
       
   576     Gear^.Y:= Gear^.Y - 0.08 * Steps;
       
   577 
       
   578 end;
       
   579 
       
   580 procedure doStepHealthTag(Gear: PVisualGear; Steps: Longword);
       
   581 var s: shortstring;
       
   582 begin
       
   583 s:= '';
       
   584 
       
   585 str(Gear^.State, s);
       
   586 if Gear^.Hedgehog <> nil then
       
   587     Gear^.Tex:= RenderStringTex(s, Gear^.Hedgehog^.Team^.Clan^.Color, fnt16)
       
   588 else
       
   589     Gear^.Tex:= RenderStringTex(s, cWhiteColor, fnt16);
       
   590 
       
   591 Gear^.doStep:= @doStepHealthTagWork;
       
   592 
       
   593 if (round(Gear^.Y) > cWaterLine) and (Gear^.Frame = 0)  then
       
   594     Gear^.doStep:= @doStepHealthTagWorkUnderWater;
       
   595 
       
   596 Gear^.Y:= Gear^.Y - Gear^.Tex^.h;
       
   597 
       
   598 if Steps > 1 then
       
   599     Gear^.doStep(Gear, Steps-1);
       
   600 end;
       
   601 
       
   602 ////////////////////////////////////////////////////////////////////////////////
       
   603 procedure doStepSmokeTrace(Gear: PVisualGear; Steps: Longword);
       
   604 begin
       
   605 inc(Gear^.Timer, Steps );
       
   606 if Gear^.Timer > 64 then
       
   607     begin
       
   608     if Gear^.State = 0 then
       
   609         begin
       
   610         DeleteVisualGear(Gear);
       
   611         exit;
       
   612         end;
       
   613     dec(Gear^.State, Gear^.Timer div 65);
       
   614     Gear^.Timer:= Gear^.Timer mod 65;
       
   615     end;
       
   616 Gear^.dX:= Gear^.dX + cWindSpeedf * Steps;
       
   617 Gear^.X:= Gear^.X + Gear^.dX;
       
   618 end;
       
   619 
       
   620 ////////////////////////////////////////////////////////////////////////////////
       
   621 procedure doStepExplosionWork(Gear: PVisualGear; Steps: Longword);
       
   622 begin
       
   623 inc(Gear^.Timer, Steps);
       
   624 if Gear^.Timer > 75 then
       
   625     begin
       
   626     inc(Gear^.State, Gear^.Timer div 76);
       
   627     Gear^.Timer:= Gear^.Timer mod 76;
       
   628     if Gear^.State > 5 then
       
   629         DeleteVisualGear(Gear);
       
   630     end;
       
   631 end;
       
   632 
       
   633 procedure doStepExplosion(Gear: PVisualGear; Steps: Longword);
       
   634 var i: LongWord;
       
   635     gX,gY: LongInt;
       
   636     vg: PVisualGear;
       
   637 begin
       
   638 gX:= round(Gear^.X);
       
   639 gY:= round(Gear^.Y);
       
   640 for i:= 0 to 31 do 
       
   641     begin
       
   642     vg:= AddVisualGear(gX, gY, vgtFire);
       
   643     if vg <> nil then 
       
   644         begin
       
   645         vg^.State:= gstTmpFlag;
       
   646         inc(vg^.FrameTicks, vg^.FrameTicks)
       
   647         end
       
   648     end;
       
   649 for i:= 0 to  8 do AddVisualGear(gX, gY, vgtExplPart);
       
   650 for i:= 0 to  8 do AddVisualGear(gX, gY, vgtExplPart2);
       
   651 Gear^.doStep:= @doStepExplosionWork;
       
   652 if Steps > 1 then
       
   653     Gear^.doStep(Gear, Steps-1);
       
   654 end;
       
   655 
       
   656 
       
   657 ////////////////////////////////////////////////////////////////////////////////
       
   658 procedure doStepBigExplosionWork(Gear: PVisualGear; Steps: Longword);
       
   659 var maxMovement: LongInt;
       
   660 begin
       
   661 
       
   662 inc(Gear^.Timer, Steps);
       
   663 if (Gear^.Timer and 5) = 0 then
       
   664     begin
       
   665     maxMovement := max(1, 13 - ((Gear^.Timer * 15) div 250));
       
   666     ShakeCamera(maxMovement);
       
   667     end;
       
   668 
       
   669 if Gear^.Timer > 250 then
       
   670     DeleteVisualGear(Gear);
       
   671 end;
       
   672 
       
   673 procedure doStepBigExplosion(Gear: PVisualGear; Steps: Longword);
       
   674 var i: LongWord;
       
   675     gX,gY: LongInt;
       
   676     vg: PVisualGear;
       
   677 begin
       
   678 //ScreenFade:= sfFromWhite;
       
   679 //ScreenFadeValue:= round(60 * zoom * zoom);
       
   680 //ScreenFadeSpeed:= 5;
       
   681 gX:= round(Gear^.X);
       
   682 gY:= round(Gear^.Y);
       
   683 AddVisualGear(gX, gY, vgtSmokeRing);
       
   684 for i:= 0 to 46 do 
       
   685     begin
       
   686     vg:= AddVisualGear(gX, gY, vgtFire);
       
   687     if vg <> nil then 
       
   688         begin
       
   689         vg^.State:= gstTmpFlag;
       
   690         inc(vg^.FrameTicks, vg^.FrameTicks)
       
   691         end
       
   692     end;
       
   693 for i:= 0 to 15 do
       
   694     AddVisualGear(gX, gY, vgtExplPart);
       
   695 for i:= 0 to 15 do
       
   696     AddVisualGear(gX, gY, vgtExplPart2);
       
   697 Gear^.doStep:= @doStepBigExplosionWork;
       
   698 if Steps > 1 then
       
   699     Gear^.doStep(Gear, Steps-1);
       
   700 with mobileRecord do
       
   701     if (performRumble <> nil) and (not fastUntilLag) then
       
   702         performRumble(kSystemSoundID_Vibrate);
       
   703 end;
       
   704 
       
   705 procedure doStepChunk(Gear: PVisualGear; Steps: Longword);
       
   706 begin
       
   707 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   708 
       
   709 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
       
   710 Gear^.dY:= Gear^.dY + cGravityf * Steps;
       
   711 
       
   712 Gear^.Angle:= round(Gear^.Angle + Steps) mod cMaxAngle;
       
   713 
       
   714 if (round(Gear^.Y) > cWaterLine) and ((cReducedQuality and rqPlainSplash) = 0) then
       
   715     begin
       
   716     AddVisualGear(round(Gear^.X), round(Gear^.Y), vgtDroplet);
       
   717     DeleteVisualGear(Gear);
       
   718     end
       
   719 end;
       
   720 
       
   721 ////////////////////////////////////////////////////////////////////////////////
       
   722 procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword);
       
   723 begin
       
   724 if Gear^.FrameTicks <= Steps then
       
   725     DeleteVisualGear(Gear)
       
   726 else
       
   727     dec(Gear^.FrameTicks, Steps);
       
   728 end;
       
   729 
       
   730 ////////////////////////////////////////////////////////////////////////////////
       
   731 procedure doStepCircle(Gear: PVisualGear; Steps: Longword);
       
   732 var tmp: LongInt;
       
   733     i: LongWord;
       
   734 begin
       
   735 with Gear^ do
       
   736     if Frame <> 0 then
       
   737         for i:= 1 to Steps do
       
   738             begin
       
   739             inc(FrameTicks);
       
   740             if (FrameTicks mod Frame) = 0 then
       
   741                 begin
       
   742                 tmp:= Gear^.Tint and $FF;
       
   743                 if tdY >= 0 then
       
   744                     inc(tmp)
       
   745                 else
       
   746                     dec(tmp);
       
   747                 if tmp < round(dX) then
       
   748                     tdY:= 1;
       
   749                 if tmp > round(dY) then
       
   750                     tdY:= -1;
       
   751                 if tmp > 255 then
       
   752                     tmp := 255;
       
   753                 if tmp < 0 then
       
   754                     tmp := 0;
       
   755                 Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or Longword(tmp)
       
   756                 end
       
   757             end
       
   758 end;
       
   759 
       
   760 ////////////////////////////////////////////////////////////////////////////////
       
   761 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
       
   762 begin
       
   763 inc(Gear^.Timer, Steps);
       
   764     
       
   765 while Gear^.Timer >= 10 do
       
   766     begin
       
   767     dec(Gear^.Timer, 10);
       
   768     if WindBarWidth < Gear^.Tag then
       
   769         inc(WindBarWidth)
       
   770     else if WindBarWidth > Gear^.Tag then
       
   771         dec(WindBarWidth);
       
   772     end;
       
   773 if cWindspeedf > Gear^.dAngle then
       
   774     begin
       
   775     cWindspeedf := cWindspeedf - Gear^.Angle*Steps;
       
   776     if cWindspeedf < Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
       
   777     end
       
   778 else if cWindspeedf < Gear^.dAngle then
       
   779     begin
       
   780     cWindspeedf := cWindspeedf + Gear^.Angle*Steps;
       
   781     if cWindspeedf > Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
       
   782     end;
       
   783         
       
   784 if (WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)  then 
       
   785     DeleteVisualGear(Gear)
       
   786 end;
       
   787 ////////////////////////////////////////////////////////////////////////////////
       
   788 procedure doStepStraightShot(Gear: PVisualGear; Steps: Longword);
       
   789 begin
       
   790 Gear^.X:= Gear^.X + Gear^.dX * Steps;
       
   791 Gear^.Y:= Gear^.Y - Gear^.dY * Steps;
       
   792 
       
   793 if Gear^.FrameTicks <= Steps then
       
   794     DeleteVisualGear(Gear)
       
   795 else
       
   796     begin
       
   797     dec(Gear^.FrameTicks, Steps);
       
   798     if (Gear^.FrameTicks < 501) and (Gear^.FrameTicks mod 5 = 0) then 
       
   799         Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or (((Gear^.Tint and $000000FF) * Gear^.FrameTicks) div 500)
       
   800     end
       
   801 end;
       
   802