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