hedgewars/uGearsUtils.pas
author nemo
Thu, 15 Dec 2011 12:57:26 -0500
changeset 6531 c938a35588af
parent 6498 5678806aafca
child 6543 697e9b730189
permissions -rw-r--r--
Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     1
(*
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     4
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     8
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    13
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    17
 *)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    18
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    20
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    21
unit uGearsUtils;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    22
interface
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    23
uses uTypes;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    24
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    25
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    26
function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    27
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    28
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    29
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    30
procedure CheckHHDamage(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    31
procedure CalcRotationDirAngle(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    32
procedure ResurrectHedgehog(gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    33
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean = false);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    34
function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    35
function  CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    36
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    37
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    38
implementation
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    39
uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc,
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    40
    uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore,
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    41
    uLocale, uTextures, uRenderUtils, uRandom, uGearsList, SDLh, uDebug;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    42
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    43
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    44
var Gear: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    45
    dmg, dmgRadius, dmgBase: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    46
    fX, fY: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    47
    vg: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    48
    i, cnt: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    49
begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    50
if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    51
if Radius > 25 then KickFlakes(Radius, X, Y);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    52
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    53
if ((Mask and EXPLNoGfx) = 0) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    54
    begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    55
    vg:= nil;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    56
    if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion)
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    57
    else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    58
    if vg <> nil then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    59
        vg^.Tint:= Tint;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    60
    end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    61
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    62
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    63
if (Mask and EXPLAllDamageInRadius) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    64
    dmgRadius:= Radius shl 1
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    65
else
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    66
    dmgRadius:= Radius;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    67
dmgBase:= dmgRadius + cHHRadius div 2;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    68
fX:= int2hwFloat(X);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    69
fY:= int2hwFloat(Y);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    70
Gear:= GearsList;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    71
while Gear <> nil do
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    72
    begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    73
    dmg:= 0;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    74
    //dmg:= dmgRadius  + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    75
    //if (dmg > 1) and
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    76
    if (Gear^.State and gstNoDamage) = 0 then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    77
        begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    78
        case Gear^.Kind of
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    79
            gtHedgehog,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    80
                gtMine,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    81
                gtBall,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    82
                gtMelonPiece,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    83
                gtGrenade,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    84
                gtClusterBomb,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    85
            //    gtCluster, too game breaking I think
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    86
                gtSMine,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    87
                gtCase,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    88
                gtTarget,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    89
                gtFlame,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    90
                gtExplosives,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    91
                gtStructure: begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    92
// Run the calcs only once we know we have a type that will need damage
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    93
                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    94
                            dmg:= dmgBase - max(hwRound(Distance(Gear^.X - fX, Gear^.Y - fY)),Gear^.Radius);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    95
                        if dmg > 1 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    96
                            begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    97
                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    98
                            //AddFileLog('Damage: ' + inttostr(dmg));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    99
                            if (Mask and EXPLNoDamage) = 0 then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   100
                                begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   101
                                if not Gear^.Invulnerable then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   102
                                    ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   103
                                else
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   104
                                    Gear^.State:= Gear^.State or gstWinner;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   105
                                end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   106
                            if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   107
                                begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   108
                                DeleteCI(Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   109
                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - fX)/(Gear^.Density/_3);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   110
                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - fY)/(Gear^.Density/_3);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   111
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   112
                                Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   113
                                if not Gear^.Invulnerable then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   114
                                    Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   115
                                Gear^.Active:= true;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   116
                                if Gear^.Kind <> gtFlame then FollowGear:= Gear
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   117
                                end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   118
                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   119
                                Gear^.Hedgehog^.Effects[hePoisoned] := true;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   120
                            end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   121
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   122
                        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   123
                gtGrave: begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   124
// Run the calcs only once we know we have a type that will need damage
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   125
                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   126
                            dmg:= dmgBase - hwRound(Distance(Gear^.X - fX, Gear^.Y - fY));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   127
                        if dmg > 1 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   128
                            begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   129
                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   130
                            Gear^.dY:= - _0_004 * dmg;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   131
                            Gear^.Active:= true
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   132
                            end
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   133
                        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   134
            end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   135
        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   136
    Gear:= Gear^.NextGear
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   137
    end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   138
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   139
if (Mask and EXPLDontDraw) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   140
    if (GameFlags and gfSolidLand) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   141
        begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   142
        cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   143
        if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   144
            for i:= 0 to cnt do
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   145
                AddVisualGear(X, Y, vgtChunk)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   146
        end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   147
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   148
uAIMisc.AwareOfExplosion(0, 0, 0)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   149
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   150
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   151
function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   152
var i: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   153
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   154
(* Invulnerability cannot be placed in here due to still needing kicks
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   155
   Not without a new damage machine.
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   156
   King check should be in here instead of ApplyDamage since Tiy wants them kicked less
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   157
*)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   158
i:= _1;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   159
if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then i:= _1_5;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   160
if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   161
   ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   162
else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   163
   ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   164
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   165
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   166
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   167
var s: shortstring;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   168
    vampDmg, tmpDmg, i: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   169
    vg: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   170
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   171
  if Damage = 0 then exit; // nothing to apply
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   172
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   173
    if (Gear^.Kind = gtHedgehog) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   174
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   175
    Gear^.LastDamage := AttackerHog;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   176
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   177
    Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   178
    HHHurt(Gear^.Hedgehog, Source);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   179
    AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   180
    tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   181
    if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   182
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   183
        if cVampiric then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   184
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   185
            vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   186
            if vampDmg >= 1 then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   187
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   188
                // was considering pulsing on attack, Tiy thinks it should be permanent while in play
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   189
                //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   190
                inc(CurrentHedgehog^.Gear^.Health,vampDmg);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   191
                str(vampDmg, s);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   192
                s:= '+' + s;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   193
                AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   194
                RenderHealth(CurrentHedgehog^);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   195
                RecountTeamHealth(CurrentHedgehog^.Team);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   196
                i:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   197
                while i < vampDmg do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   198
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   199
                    vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   200
                    if vg <> nil then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   201
                        with vg^ do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   202
                            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   203
                            Tint:= $FF0000FF;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   204
                            State:= ord(sprHealth)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   205
                            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   206
                    inc(i, 5);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   207
                    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   208
                end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   209
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   210
        if ((GameFlags and gfKarma) <> 0) and
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   211
           ((GameFlags and gfInvulnerable) = 0) and
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   212
           (not CurrentHedgehog^.Gear^.Invulnerable) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   213
           begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   214
           inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   215
           CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   216
           spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   217
           end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   218
        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   219
        end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   220
    end else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   221
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   222
        Gear^.Hedgehog:= AttackerHog;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   223
        end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   224
    inc(Gear^.Damage, Damage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   225
    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   226
    ScriptCall('onGearDamage', Gear^.UID, Damage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   227
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   228
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   229
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   230
var tag: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   231
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   232
tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   233
if (tag <> nil) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   234
    tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   235
AllInactive:= false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   236
HHGear^.Active:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   237
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   238
    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   239
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   240
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   241
if (Source = dsFall) or (Source = dsExplosion) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   242
    case random(3) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   243
        0: PlaySound(sndOoff1, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   244
        1: PlaySound(sndOoff2, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   245
        2: PlaySound(sndOoff3, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   246
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   247
else if (Source = dsPoison) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   248
    case random(2) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   249
        0: PlaySound(sndPoisonCough, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   250
        1: PlaySound(sndPoisonMoan, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   251
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   252
else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   253
    case random(4) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   254
        0: PlaySound(sndOw1, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   255
        1: PlaySound(sndOw2, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   256
        2: PlaySound(sndOw3, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   257
        3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   258
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   259
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   260
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   261
procedure CheckHHDamage(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   262
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   263
    dmg: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   264
    i: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   265
    particle: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   266
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   267
    if _0_4 < Gear^.dY then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   268
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   269
        dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   270
        PlaySound(sndBump);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   271
        if dmg < 1 then exit;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   272
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   273
        for i:= min(12, (3 + dmg div 10)) downto 0 do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   274
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   275
            particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   276
            if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   277
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   278
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   279
        if (Gear^.Invulnerable) then exit;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   280
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   281
        //if _0_6 < Gear^.dY then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   282
        //    PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   283
        //else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   284
        //    PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   285
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   286
        if Gear^.LastDamage <> nil then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   287
            ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   288
            else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   289
            ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   290
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   291
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   292
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   293
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   294
procedure CalcRotationDirAngle(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   295
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   296
    dAngle: real;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   297
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   298
    dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   299
    if not Gear^.dX.isNegative then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   300
        Gear^.DirAngle := Gear^.DirAngle + dAngle
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   301
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   302
        Gear^.DirAngle := Gear^.DirAngle - dAngle;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   303
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   304
    if Gear^.DirAngle < 0 then Gear^.DirAngle := Gear^.DirAngle + 360
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   305
    else if 360 < Gear^.DirAngle then Gear^.DirAngle := Gear^.DirAngle - 360
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   306
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   307
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   308
function CheckGearDrowning(Gear: PGear): boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   309
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   310
    skipSpeed, skipAngle, skipDecay: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   311
    i, maxDrops, X, Y: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   312
    vdX, vdY: real;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   313
    particle: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   314
    isSubmersible: boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   315
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   316
    // probably needs tweaking. might need to be in a case statement based upon gear type
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   317
    Y:= hwRound(Gear^.Y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   318
    if cWaterLine < Y + Gear^.Radius then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   319
        begin
6498
5678806aafca Some tiny optimizations
unc0rr
parents: 6490
diff changeset
   320
        isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   321
        skipSpeed := _0_25;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   322
        skipAngle := _1_9;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   323
        skipDecay := _0_87;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   324
        X:= hwRound(Gear^.X);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   325
        vdX:= hwFloat2Float(Gear^.dX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   326
        vdY:= hwFloat2Float(Gear^.dY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   327
        // this could perhaps be a tiny bit higher.
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   328
        if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) and
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   329
           (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   330
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   331
            Gear^.dY.isNegative := true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   332
            Gear^.dY := Gear^.dY * skipDecay;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   333
            Gear^.dX := Gear^.dX * skipDecay;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   334
            CheckGearDrowning := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   335
            PlaySound(sndSkip)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   336
            end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   337
        else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   338
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   339
            if not isSubmersible then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   340
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   341
                CheckGearDrowning := true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   342
                Gear^.State := gstDrowning;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   343
                Gear^.RenderTimer := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   344
                if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) and 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   345
                   (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   346
                    if Gear^.Kind = gtHedgehog then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   347
                        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   348
                        if Gear^.Hedgehog^.Effects[heResurrectable] then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   349
                            ResurrectHedgehog(Gear)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   350
                        else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   351
                            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   352
                            Gear^.doStep := @doStepDrowningGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   353
                            Gear^.State := Gear^.State and (not gstHHDriven);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   354
                            AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   355
                            end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   356
                        end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   357
                    else Gear^.doStep := @doStepDrowningGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   358
                    if Gear^.Kind = gtFlake then exit // skip splashes 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   359
                end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   360
            if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   361
               (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01))) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   362
                // don't play splash if they are already way past the surface
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   363
                PlaySound(sndSplash)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   364
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   365
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   366
        if ((cReducedQuality and rqPlainSplash) = 0) and 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   367
           (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   368
             (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01)))) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   369
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   370
            AddVisualGear(X, cWaterLine, vgtSplash);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   371
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   372
            maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   373
            for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   374
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   375
                particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   376
                if particle <> nil then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   377
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   378
                    particle^.dX := particle^.dX - vdX / 10;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   379
                    particle^.dY := particle^.dY - vdY / 5;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   380
                    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   381
                end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   382
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   383
        if isSubmersible and (CurAmmoGear^.Pos = 0) then CurAmmoGear^.Pos := 1000
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   384
        end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   385
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   386
        CheckGearDrowning := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   387
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   388
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   389
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   390
procedure ResurrectHedgehog(gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   391
var tempTeam : PTeam;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   392
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   393
    AttackBar:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   394
    gear^.dX := _0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   395
    gear^.dY := _0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   396
    gear^.Damage := 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   397
    gear^.Health := gear^.Hedgehog^.InitialHealth;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   398
    gear^.Hedgehog^.Effects[hePoisoned] := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   399
    if not CurrentHedgehog^.Effects[heResurrectable] then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   400
        with CurrentHedgehog^ do 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   401
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   402
            inc(Team^.stats.AIKills);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   403
            FreeTexture(Team^.AIKillsTex);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   404
            Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   405
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   406
    tempTeam := gear^.Hedgehog^.Team;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   407
    DeleteCI(gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   408
    FindPlace(gear, false, 0, LAND_WIDTH, true); 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   409
    if gear <> nil then begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   410
        RenderHealth(gear^.Hedgehog^);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   411
        ScriptCall('onGearResurrect', gear^.uid);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   412
        gear^.State := gstWait;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   413
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   414
    RecountTeamHealth(tempTeam);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   415
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   416
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   417
function CountNonZeroz(x, y, r, c: LongInt): LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   418
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   419
    count: LongInt = 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   420
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   421
if (y and LAND_HEIGHT_MASK) = 0 then
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   422
    for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   423
        if Land[y, i] <> 0 then
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   424
            begin
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   425
            inc(count);
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   426
            if count = c then exit(count)
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   427
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   428
CountNonZeroz:= count;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   429
end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   430
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   431
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   432
var x: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   433
    y, sy: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   434
    ar: array[0..511] of TPoint;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   435
    ar2: array[0..1023] of TPoint;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   436
    cnt, cnt2: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   437
    delta: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   438
    reallySkip, tryAgain: boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   439
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   440
reallySkip:= false; // try not skipping proximity at first
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   441
tryAgain:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   442
while tryAgain do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   443
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   444
    delta:= 250;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   445
    cnt2:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   446
    repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   447
        x:= Left + LongInt(GetRandom(Delta));
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   448
        repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   449
            inc(x, Delta);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   450
            cnt:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   451
            y:= min(1024, topY) - 2 * Gear^.Radius;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   452
            while y < cWaterLine do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   453
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   454
                repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   455
                    inc(y, 2);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   456
                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   457
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   458
                sy:= y;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   459
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   460
                repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   461
                    inc(y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   462
                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   463
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   464
                if (y - sy > Gear^.Radius * 2) and
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   465
                   (((Gear^.Kind = gtExplosives)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   466
                       and (y < cWaterLine)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   467
                       and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil))
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   468
                       and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius))
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   469
                   or
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   470
                     ((Gear^.Kind <> gtExplosives)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   471
                       and (y < cWaterLine)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   472
                       and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   473
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   474
                    ar[cnt].X:= x;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   475
                    if withFall then ar[cnt].Y:= sy + Gear^.Radius
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   476
                                else ar[cnt].Y:= y - Gear^.Radius;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   477
                    inc(cnt)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   478
                    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   479
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   480
                inc(y, 45)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   481
                end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   482
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   483
            if cnt > 0 then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   484
                with ar[GetRandom(cnt)] do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   485
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   486
                    ar2[cnt2].x:= x;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   487
                    ar2[cnt2].y:= y;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   488
                    inc(cnt2)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   489
                    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   490
        until (x + Delta > Right);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   491
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   492
        dec(Delta, 60)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   493
    until (cnt2 > 0) or (Delta < 70);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   494
    if (cnt2 = 0) and skipProximity and (not reallySkip) then tryAgain:= true
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   495
    else tryAgain:= false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   496
    reallySkip:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   497
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   498
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   499
if cnt2 > 0 then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   500
    with ar2[GetRandom(cnt2)] do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   501
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   502
        Gear^.X:= int2hwFloat(x);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   503
        Gear^.Y:= int2hwFloat(y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   504
        AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   505
        end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   506
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   507
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   508
    OutError('Can''t find place for Gear', false);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   509
    if Gear^.Kind = gtHedgehog then Gear^.Hedgehog^.Effects[heResurrectable] := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   510
    DeleteGear(Gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   511
    Gear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   512
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   513
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   514
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   515
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   516
var t: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   517
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   518
t:= GearsList;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   519
rX:= sqr(rX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   520
rY:= sqr(rY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   521
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   522
while t <> nil do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   523
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   524
    if (t <> Gear) and (t^.Kind = Kind) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   525
        if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   526
        exit(t);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   527
    t:= t^.NextGear
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   528
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   529
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   530
CheckGearNear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   531
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   532
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   533
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   534
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   535
var t: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   536
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   537
t:= GearsList;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   538
rX:= sqr(rX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   539
rY:= sqr(rY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   540
while t <> nil do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   541
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   542
    if t^.Kind in Kind then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   543
        if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   544
            exit(t);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   545
    t:= t^.NextGear
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   546
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   547
CheckGearsNear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   548
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   549
end.