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